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®ion=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:
精彩评论