Recently started to contact Ajax cross-domain request problem, compared to the network said a lot of, I said here is more superficial.
On the question of why cross-domain, the actual requirement is that when the site project is deployed on a domain name, the domain can be a good solution to the problem of Web site lag (having multiple servers is another matter).
This practice is now very common, look at a few sites more carefully can see the doorway.
Compare the Ajax requests with the cross-domain requests before the cross-domain:
Before:
function (data) { alert (data); Window.location.reload (); });
Here is the Post method (generally more convenient, but not proficient in Ajax is not recommended to start with this said to use), you can also use get.
To say, cross-domain requests do not support post mode! Nor does it mean that there is no support at all, using a POST request when doing cross-domain restrictions on the encoding type, allowing only content-type to
One of application/x-www-form-urlencoded, Multipart/form-data, or Text/plain.
........
After:
$.ajax ({type: "GET" false Url:wwwurl + "/home/index" " Jsonp " " callback ", // to the request handler or page, identify the JSONP callback function name (typically: callback). Jsonpcallback: function () {}, // callback. Success: function
Here you can compare the differences between the two ways.
The Jsonpcallback property is followed by an anonymous function, in fact, this should be called from another "domain" returned function name, function in the domain JS inside, return back directly call on the line, remember to take the argument!
The service side of the code will not show, it is passed a callback parameter validation is empty, the conditional return to a JSON opposite, containing the operation of the data returned when the state message,success inside the call is data. Message.
Baidu Library has a detailed description of the relevant, do not repeat it here.
Ajax request data across domains