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

WBOY
Release: 2016-05-17 08:55:23
Original
979 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) {…}内的任何操作
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!