在 jQuery 1.2 中,您可以通过使用JSONP 形式的回调函数来加载其他网域的JSON数据,如 “myurl?callback=?”。jQuery 将自动替换 ? 为正确的函数名,以执行回调函数。 注意:此行以后的代码将在这个回调函数执行前执行。
$.getJSON('http://192.168.0.144/test/testjson.php?callback=?',function (json){ alert(json[1].name); php代码: $arr[] = array('id'=>1,'name'=>'PHP'); $arr[] = array('id'=>2,'name'=>'JSP'); $json_str = json_encode($arr); echo $_GET['callback'].'('.$json_str.')'; ?> jquery中利用getJSON这个方法就可以轻松搞定跨域传值问题了。