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
92
votes
8 answers

How can I send the "&" (ampersand) character via AJAX?

I want to send a few variables and a string with the POST method from JavaScript. I get the string from the database, and then send it to a PHP page. I am using an XMLHttpRequest object. The problem is that the string contains the character & a few…
candino
  • 1,197
  • 2
  • 10
  • 11
91
votes
5 answers

How do I know if jQuery has an Ajax request pending?

I'm having some problems with a jQuery control we made. Suppose you have a dropdownlist that allows you to enter the ID of the item you're looking for, and when you press ENTER or lose focus in a textbox it validates via jQuery that the ID you…
sabanito
  • 1,471
  • 1
  • 11
  • 17
89
votes
5 answers

A CORS POST request works from plain JavaScript, but why not with jQuery?

I'm trying to make a Cross Origin post request, and I got it working in plain JavaScript like this: var request = new XMLHttpRequest(); var params = "action=something"; request.open('POST', url, true); request.onreadystatechange = function() {if…
Magmatic
  • 1,349
  • 1
  • 12
  • 22
88
votes
4 answers

POST data in JSON format

I have some data that I need to convert to JSON format and then POST it with a JavaScript function.
Randy Smith
85
votes
8 answers

loading json data from local file into React JS

I have a React component and I want to load in my JSON data from a file. The console log currently doesn't work, even though I'm creating the variable data as a global 'use strict'; var React = require('react/addons'); // load in JSON data from…
Desmond
  • 1,386
  • 2
  • 19
  • 32
76
votes
8 answers

How do I get the HTTP status code with jQuery?

I want to check if a page returns the status code 401. Is this possible? Here is my try, but it only returns 0. $.ajax({ url: "http://my-ip/test/test.php", data: {}, complete: function(xhr, statusText){ alert(xhr.status); …
horgen
  • 2,093
  • 9
  • 29
  • 34
72
votes
7 answers

Web Scraping in a Google Chrome Extension (JavaScript + Chrome APIs)

What are the best options for performing Web Scraping of a not currently open tab from within a Google Chrome Extension with JavaScript and whatever more technologies are available. Other JavaScript-libraries are also accepted. The important thing…
72
votes
2 answers

$http doesn't send cookie in Requests

We are working on a RESTful Webservice with AngularJS and Java Servlets. When the user logs in, our backend sends a "Set-Cookie" header to the frontend. In Angular we access the header via $cookies (ngCookie - module) and set it. Now that the user…
Tim Daubenschütz
  • 1,676
  • 4
  • 19
  • 37
70
votes
14 answers

How secure is a HTTP POST?

Is a POST secure enough to send login credentials over? Or is an SSL connection a must?
Matt
  • 4,659
  • 11
  • 37
  • 45
69
votes
8 answers

"not well-formed" error in Firefox when loading JSON file with XMLHttpRequest

I'm getting a "not well-formed" error in the error console of Firefox 3.0.7 when the JavaScript on my page loads a text file containing an object in JavaScript Object Notation format. If the file contains nothing but the JSON object, it produces the…
A. Levy
  • 25,944
  • 6
  • 36
  • 55
67
votes
8 answers

How to check if the request is an AJAX request with PHP

I would like to check server-side if a request to my php page is an ajax request or not. I saw two ways to do this: First way: sending a GET parameter in the request which tells the page that this is an AJAX request…
BackSlash
  • 20,445
  • 19
  • 77
  • 124
67
votes
2 answers

When loading external data, console says: XHR finished loading

Is there a way to hide the "XHR finished loading" messages in the console?
Kriem
  • 8,533
  • 14
  • 67
  • 117
66
votes
5 answers

How to Detect Cross Origin (CORS) Error vs. Other Types of Errors for XMLHttpRequest() in Javascript

I'm trying to detect when an XMLHttpRequest() fails due to a Cross Origin Error as opposed to a bad request. For example: ajaxObj=new XMLHttpRequest() ajaxObj.open("GET", url, true); ajaxObj.send(null); Consider 4 cases for url: Case…
user2871305
  • 852
  • 1
  • 6
  • 6
64
votes
1 answer

Upload File With Ajax XmlHttpRequest

Hi i am trying to send file with xmlhttprequest with this code. var url= "http://localhost:80/...."; $(document).ready(function(){ document.getElementById('upload').addEventListener('change', function(e) { var file = this.files[0]; …
Sedat Başar
  • 3,361
  • 3
  • 22
  • 28
64
votes
3 answers

What is the boundary parameter in an HTTP multi-part (POST) Request?

I am trying to develop a sidebar gadget that automates the process of checking a web page for the evolution of my transfer quota. I am almost at it but there is one last step I need to get it working: Sending an HttpRequest with the correct POST…
m6a-uds
  • 905
  • 2
  • 8
  • 12