【发布时间】:2013-09-26 15:31:07
【问题描述】:
我已经按照本教程的说法创建了一个服务,当我在浏览器中输入这个 url 时,我可以看到:
http://{localhost}:8888/drupal2/test_test/node/1.jsonp
或
http://{localhost}:8888/drupal2/test_test/node/1.json
或
http://{localhost}:8888/drupal2/test_test/system/connect.json
我得到了 json 回调。但是当它在 jquery 代码中时,我得到了
XMLHttpRequest 无法加载 http://{localhost}:8888/drupal2/test_test/node/1.json?type=post&format=json。 来源 http://{localhost}:8383 不允许 访问控制允许来源。
为什么会这样?
jQuery 代码:
$(function() {
var urlis = "http://localhost:8888/drupal2/test_test/node/1.json";
$.getJSON(urlis, {
type: 'post',
format: "json"
}).done(function(afterdone) {
console.log("JSONP Data");
})
.fail(function(error) {
console.log("NO!");
});
});
【问题讨论】:
标签: php jquery web-services drupal-7