Home  >  Article  >  Backend Development  >  php jq jquery getJSON跨域提交数据完整版_php技巧

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

WBOY
WBOYOriginal
2016-05-17 08:55:23997browse

前端请求端:

复制代码 代码如下:

<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) {…}内的任何操作
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