Home  >  Article  >  php教程  >  浅析php中jsonp的跨域实例

浅析php中jsonp的跨域实例

WBOY
WBOYOriginal
2016-06-13 11:46:23674browse

我们现在www.test.com这个域名下面有这么个html文件testjsonp.html:

复制代码 代码如下:



 
 


     Untitled Page
     
     
    
 
 
 

注意,要真正运行上面的代码可能需要jquery的文件,你可以将改为你目录中jquery的文件路径:
如:
然后,你可以再找个另外一个域名的web目录,将文件jsonp.php:

复制代码 代码如下:


$callback = $_GET["callback"];
$a = array(
 'code'=>'CA1998',
    'price'=>'6000',
    'tickets'=>20,
    'func'=>$callback,
);
$result = json_encode($a);
echo "flightHandler($result)";
exit;


放到这个目录下面去。这样就可以测试了。
直接在浏览器访问testjsonp.html.就可以看到效果了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn