$.ajax timeout, next request is err: "abc was not called"
Basically what I'm trying to do is:
1) make 1st a jsonp get request to a url
This call may get 404
2) if the first call fails, make a jsonp get request to a different url
If the first call fails due to timeout (404 error) then the second call fails with an error that the first call jsonpCallback ("abc") was not called. I don't understand how the first call could be effecting the second call.
Here's some example code (it's more code than necessary but for clarity sake):
- var failed = false;
- var secondAttempt = false;
- var json = {
- userLogin: username,
- password: password,
- database: dbName
- };
- var done = function (newResults) {
- console.log("Done")
- };
- var fail = function (jqXHR, status, error) {
- failed = true;
- this.jsonpCallback = null;
- if(secondAttempt){
- console.log("Failed")
- }
- };
- var always = function () {
- if(failed && !secondAttempt){
- secondAttempt = true;
- $.ajax({
- type: "GET",
- url: serverUrl + requestPath + "Authenticate" + "?JSONP=?",
- dataType: "jsonp",
- crossDomain: true,
- timeout: 3000,
- data: jsonp,
- jsonpCallback: "abc"
- })
- .done(done)
- .fail(fail)
- .always(always);
- }
- };
- $.ajax({
- type: "GET",
- url: serverUrl + newRequestPath + "Authenticate" + "?JSONP=?",
- dataType: "jsonp",
- crossDomain: true,
- timeout: 3000,
- data: json,
- jsonpCallback: "xyz"
- })
- .done(done)
- .fail(fail)
- .always(always);