[英]How to make Request.JSON work cross-domain (Mootools)?
我正在从服务器test1.com执行index.html
文件。 Mootools库文件包含在此index.html
文件中。
以下是调用PHP页面的脚本:
<script>
var request = new Request.JSON({
url: 'http://test1.com/ajaxtest.php',
onSuccess: function(data) {
// the request was completed.
alert(JSON.stringify(data));
}
}).send();
</script>
<?php
$arr['age'] = 30;
$arr['place'] = 'London';
echo json_encode($arr); exit;
?>
在执行index.html
,我得到了正确的输出”
{“年龄”:30,“地点”:“伦敦”}
现在, ajaxtest.php
位于另一个服务器上,例如test2.com。 如何更改上述脚本以使其更早地工作?
不确定现在是否对您有帮助。
您需要使用Request.JSONP Class对象发出跨站点请求:
new Request.JSONP({
url: "http://search.twitter.com/search.json",
data: {
q: "Arsenal"
},
onComplete: function(tweets) {
// Log the result to console for inspection
console.info("Twitter returned: ",tweets);
}
}).send();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.