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

12041 questions
3134
votes
34 answers

How can I upload files asynchronously with jQuery?

I would like to upload a file asynchronously with jQuery. $(document).ready(function () { $("#uploadbutton").click(function () { var filename = $("#file").val(); $.ajax({ type: "POST", url:…
Sergio del Amo
  • 76,835
  • 68
  • 152
  • 179
1347
votes
35 answers

Access-Control-Allow-Origin Multiple Origin Domains?

Is there a way to allow multiple cross-domains using the Access-Control-Allow-Origin header? I'm aware of the *, but it is too open. I really want to allow just a couple domains. As an example, something like this: Access-Control-Allow-Origin:…
Thomas J Bradley
  • 13,726
  • 3
  • 18
  • 8
688
votes
13 answers

Send POST data using XMLHttpRequest

I'd like to send some data using an XMLHttpRequest in JavaScript. Say I have the following form in HTML:
Jack Greenhill
  • 10,240
  • 12
  • 38
  • 70
594
votes
17 answers

“Origin null is not allowed by Access-Control-Allow-Origin” error for request made by application running from a file:// URL

I'm developing a page that pulls images from Flickr and Panoramio via jQuery's AJAX support. The Flickr side is working fine, but when I try to $.get(url, callback) from Panoramio, I see an error in Chrome's console: XMLHttpRequest cannot load…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
530
votes
23 answers

How to read a local text file in the browser?

I’m trying to implemennt a simple text file reader by creating a function that takes in the file’s path and converts each line of text into a char array, but it’s not working. function readTextFile() { var rawFile = new XMLHttpRequest(); …
Danny
  • 9,199
  • 16
  • 53
  • 75
377
votes
9 answers

How many concurrent AJAX (XmlHttpRequest) requests are allowed in popular browsers?

In Firefox 3, the answer is 6 per domain: as soon as a 7th XmlHttpRequest (on any tab) to the same domain is fired, it is queued until one of the other 6 finish. What are the numbers for the other major browsers? Also, are there ways around these…
Michael Gundlach
  • 106,555
  • 11
  • 37
  • 41
368
votes
18 answers

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

I'm making an Ajax.request to a remote PHP server in a Sencha Touch 2 application (wrapped in PhoneGap). The response from the server is the following: XMLHttpRequest cannot load http://nqatalog.negroesquisso.pt/login.php. Origin…
Ricardo
  • 11,609
  • 8
  • 27
  • 39
348
votes
8 answers

Proper way to catch exception from JSON.parse

I’m using JSON.parse on a response that sometimes contains a 404 response. In the cases where it returns 404, is there a way to catch an exception and then execute some other code? data = JSON.parse(response, function (key, value) { var type; …
prostock
  • 9,327
  • 19
  • 70
  • 118
329
votes
10 answers

Why am I getting an OPTIONS request instead of a GET request?

it does an OPTIONS request to that URL, and then the…
Paul Tarjan
  • 48,968
  • 59
  • 172
  • 213
307
votes
11 answers

Why does my http://localhost CORS origin not work?

I am stuck with this CORS problem, even though I set the server (nginx/node.js) with the appropriate headers. I can see in Chrome Network pane -> Response Headers: Access-Control-Allow-Origin:http://localhost which should do the trick. Here's the…
whadar
  • 4,181
  • 4
  • 19
  • 21
297
votes
13 answers

Pure JavaScript Send POST Data Without a Form

Is there a way to send data using the POST method without a form and without refreshing the page using only pure JavaScript (not jQuery $.post())? Maybe httprequest or something else (just can't find it now)?
John
  • 7,500
  • 16
  • 62
  • 95
278
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
  • 4,270
  • 4
  • 22
  • 35
260
votes
10 answers

Edit and replay XHR chrome/firefox etc?

I have 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
  • 2,797
  • 3
  • 14
  • 22
248
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
244
votes
4 answers

How to get the response of XMLHttpRequest?

I'd like to know how to use XMLHttpRequest to load the content of a remote URL and have the HTML of the accessed site stored in a JS variable. Say, if I wanted to load and alert() the HTML of http://foo.com/bar.php, how would I do that?
Rohan
  • 3,645
  • 4
  • 22
  • 16
1
2 3
99 100