JQUERY 中封装的JSONP请求方法
1.index.html 中的javascript
$(function(){
$.ajax({
type: "GET",
async:false,
url: "http://www.vm.com:81/index.php", //跨域请求的地址
data:{‘birt‘:2016},
dataType: ‘jsonp‘,
jsonp: ‘jsoncallback‘,
success: function(msg){
alert("msg:"+JSON.stringify(msg));
},
error:function(msg){
//alert("msg:"+JSON.stringify(msg));
}
});
});
2.index.php
$cb = $_GET["jsoncallback"];
$birt = $_GET["birt"];
$varArr = array("username"=>"lianruihong","age"=>20,"birt"=>$birt);
echo $cb."(".json_encode($varArr).")";
时间: 2024-10-13 11:17:27