$.ajax({ type:"get", url: "http://localhost/test/a.php", dataType: "jsonp", jsonp: "callback", jsonpCallback:'jsonpCallback', //必须
success: function(json) { alert('success'); }, error:function() { alert('error'); } });
<?php $callback = isset($_GET['callback']) ? trim($_GET['callback']) : ''; //jsonp回调参数,必需 $date["msg"]="success"; $tmp= json_encode($date); //json 数据 echo $callback.'('.$tmp.')'; //返回格式,必需
//返回的格式为:jsonpCallback({"msg":"success"}) ?>