4

我正在执行index.html来自服务器 test1.com 的文件。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>

ajaxtest.php

<?php
  $arr['age'] = 30;
  $arr['place'] = 'London';
  echo json_encode($arr); exit;
?>

在执行时index.html,我得到了正确的输出”

{“年龄”:30,“地点”:“伦敦”}

现在,ajaxtest.php驻留在另一台服务器上,例如 test2.com。如何更改上述脚本以使其像以前一样工作?

4

1 回答 1

2

现在不确定这是否对您有帮助。

您需要使用 Request.JSONP 类对象进行跨站请求:

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(); 
于 2013-12-27T10:41:19.437 回答