Questions tagged [jqxhr]

jqXHR is a jQuery object that provides a JavaScript cross-browser-compatible superset (wrapper) object for the browser-implemented XMLHttpRequest (XHR) object.

The jQuery XMLHttpRequest object (jqXHR in short) is returned by jQuery's $.ajax() method and as of jQuery 1.5, it is a superset of the browser's native XMLHttpRequest object. Among several properties and methods, it contains responseText, responseXML, and the getResponseHeader() method.

Example:

// send an AJAX request as usual
$.ajax('data.php'))    
  .done(function() {
    // the AJAX request was successful
    console.log('$.ajax succeeded');
  })      
  .fail(function() {
    // the AJAX request was unsuccessful
    console.log('$.ajax failed');
  })  
  .always(function() {
    // from jQuery 1.6, this function will always be called
    // either the AJAX request was successful or unsuccessful
    console.log('$.ajax either succeeded or failed');
  });

Resources

Related Tags

177 questions
54
votes
4 answers

jQuery.post( ) .done( ) and success:

jQuery documentation on jQuery.post( ) // Assign handlers immediately after making the request, // and remember the jqxhr object for this request var jqxhr = $.post( "example.php", function() { alert( "success" ); }) .done(function() { …
KaekeaSchmear
  • 1,548
  • 5
  • 18
  • 30
38
votes
5 answers

Why is jqXHR.responseText returning a string instead of a JSON object?

I have an $.ajax() request with the dataType set to "json." The server is returning JSON with the correct mime type of "application/json." And yet the responseText in my jqXHR object is always a string. What am I doing wrong? Is this how it's…
user603284
30
votes
5 answers

How do I SET a Cookie (header) with XMLHttpRequest in JavaScript?

I'm trying to set a Cookie in a XSS request using XMLHttpRequest. I found the XMLHttpRequest Specification, and section 4.6.2-5 does seem to suggest that setting Cookie, Cookie2, and some other headers are not allowed, but I was hoping there was a…
barryred
  • 1,103
  • 1
  • 17
  • 27
26
votes
5 answers

CORS pre-flight comes back with Access-Control-Allow-Origin:*, browser still fails request

Triggering an AJAX GET to http://qualifiedlocalhost:8888/resource.json kicks off the expected CORS pre-flight, which looks like it comes back correctly: Pre-flight OPTIONS request Request URL:http://qualifiedlocalhost:8888/resource.json Request…
tnunamak
  • 2,069
  • 3
  • 22
  • 34
25
votes
6 answers

When performing post via ajax, Bad Request is returned instead of the JSON result

Javascript jqXHR = $.ajax({ url: $frm.attr("action"), type: "POST", dataType: "json", cache: false, headers: headers, contentType: "application/json;charset=UTF-8", data: ko.mapping.toJSON(data, map), beforeSend: function(x) { if (x &&…
ridermansb
  • 10,779
  • 24
  • 115
  • 226
21
votes
4 answers

Ajax GET url on error jqxhr

I have an ajax request which I am deliberately failing from my server side code to trigger the error handling event. I was wondering if it was possible here to get the URL it attempted? I want to grab that URL and inject it into a hyper link and…
Dr Schizo
  • 4,045
  • 7
  • 38
  • 77
16
votes
1 answer

Ajax not working with SSL on IE error code 12019

I am working on a web application built on Java, JSP, Ajax the servers are JBoss with front in Apche 2 server. The application is accessed over the internet. clients are using mostly IE 7, 8, 9 Browsers. The application was working perfectly…
Tayab Hussain
  • 831
  • 9
  • 16
14
votes
3 answers

When a response to $.ajax is 301, can I programmatically get the new URL?

Is there a way to get the URL you are ultimately redirected to when the response to an xhr request is 301? I have a site that contains numerous legacy URLs from an older version, which return 301 responses to the correct new URL. For utility…
BenWillkommen
  • 1,472
  • 13
  • 21
12
votes
3 answers

OPTIONS 405 (Method Not Allowed) regardless server sends Access-Control-Allow-Methods:OPTIONS, GET, HEAD, POST

I'm trying to make cross-domain request and my server is configured to send the following headers: Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:x-requested-with, Authorization Access-Control-Allow-Methods:OPTIONS, GET, HEAD,…
Spadar Shut
  • 15,111
  • 5
  • 47
  • 54
11
votes
2 answers

Make a http request with ajax for basic authorization and cors

The config for my httpd server 111.111.111.111 (supposed). Config for cors and basic auth in /etc/httpd/conf/httpd.conf. Options Indexes FollowSymLinks AllowOverride AuthConfig Require all granted Header…
showkey
  • 482
  • 42
  • 140
  • 295
10
votes
2 answers

jQuery Ajax access custom response headers

I'm using some API, and I noticed that in the response I have this: I'd need to read the "x-dl-units-left", but I get null: $.ajax(ajaxConfig).done(function(response, textStatus, xhr){ var left = xhr.getResponseHeader("x-dl-units-left"); //null …
Sampgun
  • 2,822
  • 1
  • 21
  • 38
10
votes
1 answer

How to get a custom error message from Web Api to jQuery.ajax?

This code uses the Microsoft Web Api Http stack and jQuery. How do I get a custom error message, created by an HttpError parameter to CreateErrorResponse(), displayed by jQuery's deferred.fail()? An example of creating an error response for test…
Boggin
  • 3,251
  • 3
  • 33
  • 48
9
votes
2 answers

How to get jQuery.ajax response status?

Is there any way to know if the jqXHR object returned was redirected from another request? For example, having the following code: jQuery.ajax({ type: 'POST', url: 'http://example.com/page.html', …
Luis
  • 91
  • 1
  • 1
  • 2
8
votes
3 answers

How to handle AJAX response when broken pipe happens?

I have a (Spring Boot 1.5) REST server handling file uploads (multipart/form-data) and a JS client using jQuery fileupload. In most cases it works fine but when I want to upload a larger file (about 4MB), the server figures out it is above the limit…
Arne Burmeister
  • 20,046
  • 8
  • 53
  • 94
7
votes
2 answers

Reasons not to use native XMLHttpRequest - why is $.ajax mandatory?

I'm writing an app that: absolutely relies on sending data to server via Javascript must not have JQuery library included in code. (I don't know if my code will be included in web pages that already have jquery lib, I do not know if there's…
Miloš Đakonović
  • 3,751
  • 5
  • 35
  • 55
1
2 3
11 12