Questions tagged [xmlhttprequest]

XMLHttpRequest (XHR) is a JavaScript object that exposes an API for making asynchronous HTTP requests from frontend code running a Web browser — that is, for enabling the programming technique known as AJAX. The XHR API is a legacy API. It has been superseded by the Fetch API.

Example usage

function reqListener () {
      console.log(this.responseText);
}
    
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", "http://www.example.org/example.txt");
oReq.send();

Taken from mozilla.org.

See also

11269 questions
193
votes
1 answer

jQuery posting valid json in request body

So according to the jQuery Ajax docs, it serializes data in the form of a query string when sending requests, but setting processData:false should allow me to send actual JSON in the body. Unfortunately I'm having a hard time determining first, if…
brad
  • 30,001
  • 27
  • 98
  • 151
193
votes
3 answers

Fetch API vs XMLHttpRequest

I know that Fetch API uses Promises and both of them allow you to do AJAX requests to a server. I have read that Fetch API has some extra features, which aren't available in XMLHttpRequest (and in the Fetch API polyfill, since it's based on…
ilyabasiuk
  • 3,170
  • 2
  • 17
  • 31
191
votes
7 answers

Origin null is not allowed by Access-Control-Allow-Origin

I have made a small xslt file to create an html output called weather.xsl with code as follows:
dudledok
  • 2,620
  • 5
  • 21
  • 34
188
votes
10 answers

HTML5 Pre-resize images before uploading

Here's a noodle scratcher. Bearing in mind we have HTML5 local storage and xhr v2 and what not. I was wondering if anyone could find a working example or even just give me a yes or no for this question: Is it possible to Pre-size an image using the…
Jimmyt1988
  • 18,656
  • 34
  • 113
  • 210
175
votes
9 answers

Edit and replay XHR chrome/firefox etc?

I've been looking for a way to alter a XHR request made in my browser and then replay it again. Say I have a complete POST request done in my browser, and the only thing I want to change is a small value and then play it again. This would be a lot…
madsobel
  • 1,929
  • 3
  • 11
  • 21
172
votes
11 answers

Cross-Origin Request Headers(CORS) with PHP headers

I have a simple PHP script that I am attempting a cross-domain CORS request:
user1022241
155
votes
11 answers

Why am I seeing an "origin is not allowed by Access-Control-Allow-Origin" error here?

I am seeing the following error: Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin with this code: var http = new getXMLHttpRequestObject(); var url = "http://gdata.youtube.com/action/GetUploadToken"; var sendXML = '
Muhammad Usman
  • 9,182
  • 21
  • 69
  • 104
150
votes
10 answers

How to enable CORS in AngularJs

I have created a demo using JavaScript for Flickr photo search API. Now I am converting it to the AngularJs. I have searched on internet and found below configuration. Configuration: myApp.config(function($httpProvider) { …
ankitr
  • 5,512
  • 7
  • 40
  • 66
147
votes
15 answers

What does it mean when an HTTP request returns status code 0?

What does it mean when JavaScript network calls such as fetch or XMLHttpRequest, or any other type of HTTP network request, fail with an HTTP status code of 0? This doesn't seem to be a valid HTTP status code as other codes are three digits in HTTP…
mike nelson
  • 18,814
  • 13
  • 59
  • 66
142
votes
3 answers

How does JavaScript handle AJAX responses in the background?

Since JavaScript runs in a single thread, after an AJAX request is made, what actually happens in the background? I would like to get a deeper insight into this, can anyone shed some light?
aziz punjani
  • 24,673
  • 9
  • 42
  • 56
135
votes
11 answers

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '...' is therefore not allowed access

I'm using .htaccess to rewrite urls and I used html base tag in order to make it work. Now, when I try to make an ajax request I get the following error: XMLHttpRequest cannot load http://www.example.com/login.php. No 'Access-Control-Allow-Origin'…
Th3lmuu90
  • 1,677
  • 2
  • 13
  • 17
132
votes
6 answers

What is the difference between XMLHttpRequest, jQuery.ajax, jQuery.post, jQuery.get

How can I find out which method is best for a situation? Can anybody provide some examples to know the difference in terms of functionality and performance?
Rodrigues
  • 1,423
  • 2
  • 10
  • 4
131
votes
17 answers

AngularJS Error: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https

I have three files of a very simple angular js application index.html
user3422637
  • 3,369
  • 13
  • 39
  • 65
129
votes
4 answers

Allow Google Chrome to use XMLHttpRequest to load a URL from a local file

When trying to do a HTTP request using XMLHttpRequest from a local file, it basically fails due to Access-Control-Allow-Origin violation. However, I'm using the local web page myself, so I was wondering if there is any way to make Google Chrome…
pimvdb
  • 141,012
  • 68
  • 291
  • 345
128
votes
4 answers

Is onload equal to readyState==4 in XMLHttpRequest?

I am confuse about the xhr return event, as I can tell, there are not so much different between onreadystatechange --> readyState == 4 and onload, is it true? var xhr = new XMLHttpRequest(); xhr.open("Get", url, false); xhr.onreadystatechange =…
Huang
  • 1,769
  • 3
  • 14
  • 11