jquery - Ajax timeout just work once -


i coding page makes 2 ajax requests using jquery, each 1 different server. problem when each requests needs call it's own timeout event. seems the timeout event it's fired last ajax request made. if single request on page timeout works, if add second request first script's timeout not work.

i spent hours searchig how fix out success.

here example of code figure out talking about:

$(document).ready(function($) { // goes in fist script not put script tags     function getdata() {         $.ajax({         url: "urlpath",         async: false,         datatype: "jsonp",         timeout: 4000,  // timeout not work when second request present             success: function(parsed_json) {                 console.log("success fist request");             },             error: function(request, status, err) {             if (status == "timeout") {                 console.log("timeout error first request");             } else {                 console.log("unknown error fist request");             }             }         });     }); $(document).ready(function() { // goes in second script     $.ajax({     url : "urlpath.json",     datatype : "json",     timeout: 8000, // timeout work     success: function(parsed_json) {     console.log(success last request);     },     error: function(request, status, err) {         if (status == "timeout") {             console.log(timeout reached last request);         } else {             console.log(unknown error on last request);             }         }     }); }); 

any welcomed. thank in advance.

your first request jsonp, not json, you'll need handle timeout yourself: jquery ajax (jsonp) ignores timeout , doesn't fire error event


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -