wdzhangxiang 发表于 2013-1-29 08:40:23

jQuery JSONP 跨域实践(php)

jquery jsonp php实例

远程服务器上的php文件(test.php):
<?php$callback = isset($_GET["callback"])?$_GET["callback"]:"callback";$foo = isset($_GET["foo"])?$_GET["foo"]:"'";$format = isset($_GET["format"])?$_GET["format"]:""; $array = array("foo"=>$foo,"format"=>$format);echo $callback . "(". json_encode($array). ")";?> 
本地html:
<!DOCTYPE html><html><head><script src="http://code.jquery.com/jquery-1.5.js"></script></head><body><div id="images"></div><script>$.getJSON("http://your.server.com/jsonp.php?callback=?",{    foo: "bar",    format: "json"},function(data) {      alert(data.format);});</script></body></html>
页: [1]
查看完整版本: jQuery JSONP 跨域实践(php)