Home > php教程 > php手册 > php jq jquery getJSON跨域提交数据完整版

php jq jquery getJSON跨域提交数据完整版

WBOY
Release: 2016-06-13 12:47:33
Original
1432 people have browsed it

前端请求端:

复制代码 代码如下:


<script> $(function() { $.getJSON('http://test.com/aa.php?callback=?',{classid:1,num:2},function(json){ alert(json.key); }); }); </script>


被请求端:

复制代码 代码如下:


$classid=$_GET['classid'];
$num=$_GET['num'];
if($classid&&$num){$results = array("key" => "value"); echo $_GET['callback'] . '(' . json_encode($results) . ')'; }


关键在于callback这个变量 在输出json数据时要带上callbak,值一致才可以getJSON成功 否则不会执行function(json) {…}内的任何操作
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template