开发者

jQuery onsuccess not working even though firebug showing the response ok

开发者 https://www.devze.com 2023-02-25 08:40 出处:网络
I have a problem in showing an alert box inside an onsuccess function called by $.ajax. I have checked firebug, and I do receive a response in json format but for some reason the the alert is coming n

I have a problem in showing an alert box inside an onsuccess function called by $.ajax. I have checked firebug, and I do receive a response in json format but for some reason the the alert is coming neither am I able to console.log(jsonp). Below is the code:

开发者_运维问答
$.ajax({

        type: "GET",
        url: "http://maps.googleapis.com/maps/api/directions/json?origin=ajax&destination=toronto&region=ca&avoid=tolls&sensor=false",
        dataType: "jsonp",
        success: function(jsonp) {
              alert(jsonp);
            console.log(jsonp);

        }
    });

});


Read this is clearly written here : http://api.jquery.com/jQuery.ajax/

By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.

One more thing is mentioned

"jsonp": Loads in a JSON block using JSONP. Will add an extra "?callback=?" to the end of your URL to specify the callback.

If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true. This allows, for example, server-side redirection to another domain

Reference Links:

PHP-JSONP

CROSS DOMAIN DATA with jsonp

JavaScript: How do I create JSONP?

0

精彩评论

暂无评论...
验证码 换一张
取 消