jquery solve cross-domain problems

 

In the url is not a local or a server with the following URI Ajax request, although final request is shown as 200, but does not return any data,
in fact it simply request under the same domain name url or absolute path without the http and relative path request is no problem,
if the request external resources, then this is called cross-domain requests.

Due to security issues, the default browser does not support cross-domain calls, after jQuery1.2 official recommended ending the program: at the client and server
plus parameters simultaneously, so both sides are trusted then the browser will not be blocked .

 

 

 

$.ajax({
    type: "get", // request method
    async: true, // whether asynchronous
    url:"http://www.domain.net/url",
    dataType: "jsonp", // json cross-domain requests must be jsonp
    jsonp: "callbackparam", // parameter name cross-domain requests, the default is the callback
        // jsonpCallback: "successCallback", // custom cross-domain parameter values, the callback function name is the same as the default string automatically generated jQuery
    data: { "query": "civilnews"}, // request parameters

    beforeSend: function() {
        // request before processing
    },

    success: function(data) {
        // request processed successfully, and local callback exactly the same
    },

    complete: function() {
        // request completion processing
    },

    error: function() {
        // error handling request
    }
});

  

Guess you like

Origin www.cnblogs.com/zyt-bg/p/12504333.html