The example of this article analyzes the Ajax Cross-domain in jquery. Share to everyone for your reference, specific as follows:
JSONP is an unofficial protocol that allows the server-side integration script tags to return to the client, enabling Cross-domain access through JavaScript callback
Method One: The Getjson of JSONP
Js
var url = "http://localhost/mytest/jsonp_php.php?callback=?";
$.getjson (URL, {
"age": "
name": "Kitty"
}, function (data) {
alert (' Name: + Data.name + ', Age: "+ da ta.age);
};
Php
<?php
$age =$_get["age"];
$name =$_get["name"];
$jsondata = "{age: $age, Name: ' $name '}";
Echo $_get[' callback ']. ' ('. $jsondata. ') ';
? >
The $.ajax of the second JSONP
Js
$.ajax ({
type: ' Get ',
URL: ' http://localhost/mytest/jsonp_php.php ',
dataType: ' Jsonp ',
jsonp: " Callback5 ",
jsonpcallback:" Flighthandler ",
data: {
" age ":",
"name": "Kitty"
},
success : function (data) {
alert ("Name: + data.sd +", Age: + Data.aa)
}
})
Php
<?php
$age =$_get["age"];
$name =$_get["name"];
$ary =array ("SD" => "SDFG", "AA" =>23);
$jsondata =json_encode ($ary);
echo $_get[' Callback5 ']. ' ('. $jsondata. ') ';
? >
I hope this article will help you with the jquery program design.