最新消息: 新版网站上线了!!!

[工作笔记]jQuery json跨域解决方法

json跨域解决方法
jQuery:
$.ajax({
     url:"testserver.php",
     dataType: 'jsonp', // Notice! JSONP <-- P (lowercase)
     success:function(json){
         // do stuff with json (in this case an array)
         alert("Success");
     },
     error:function(){
         alert("Error");
     },
});
PHP:
<?php
$arr = array("element1","element2",array("element31","element32"));
$arr['name'] = "response";
echo $_GET['callback']."(".json_encode($arr).");";  // 09/01/12 corrected the statement
?>

转载请注明:谷谷点程序 » [工作笔记]jQuery json跨域解决方法