Skip to content Skip to sidebar Skip to footer

Can I Test If Url Is Reachable Using Ajax + Cross-domain + Jsonp?

I'm using JQuery to fetch information from an URL and display it on my page asynchronously. The URL comes from other domain, so I use JSONP to get the data. That works fine. Howeve

Solution 1:

add a timeout

$.ajax({
        type : "GET",
        url : "http://otherdomain.com/somePage.html",
        data : params,
        timeout:3000,
        dataType : "jsonp",
        jsonp : "jsonp",

        success : function (response, textS, xhr) {
            alert("ok");
        },
        error : function (xmlHttpRequest, textStatus, errorThrown) {
            alert("not ok " + errorThrown);
             if(textStatus==='timeout')
              alert("request timed out");
        }
    });

DEMO


Post a Comment for "Can I Test If Url Is Reachable Using Ajax + Cross-domain + Jsonp?"