Ticket #12279 (closed bug: invalid)
$.ajax().fail() is called even if i get a status 200 response
| Reported by: | anonymous | Owned by: | anonymous |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.8.0 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
hello there guys, i'm setting up an ajax request and get a status 200 response. .done() is not even called and instead .fail() is called. my code looks like this:
jQuery.ajax({
url : url,
type : customRequest,
dataType : 'application/x-www-form-urlencoded',
data: requestArray,
processData : true,
beforeSend : function(req) {
req.setRequestHeader('Authorization', 'someauthdataheader');
req.setRequestHeader('User-Agent','someuseragentheader');
req.setRequestHeader('Accept', 'someaccept header');
}
}).done(function(success, status, xhr) {
console.log(xhr);
console.log("i'm in done");
}).fail(function(xhr, error, status) {
console.log(xhr);
console.log("i'm in fail");
});
This is a cross domain request, in Google Chrome (Version 21.0.1180.75 m) with " --allow-cross-origin-auth-prompt --disable-web-security" as parameters to get cross domain working.
xhr.responseText gives me the exact json i was awaiting for a successfull request and xhr.status is 200.
Hope this helps.
Change History
comment:1 Changed 9 months ago by dmethvin
- Owner set to anonymous
- Status changed from new to pending
comment:2 Changed 9 months ago by anonymous
- Status changed from pending to new
console.log(xhr);
responseText: "{"status":{"statusCode":"0000","statusMessage":"Success."}}"
so my JSON response is the above string without the quotation marks that are the outermost.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

A request can fail if the JSON is not valid, there is more to a failure than just a 200 response. What does your JSON response look like?