我已经设置了一个本地运行的 Apache 服务器来托管我的 Web 应用程序(用 ExtJs 编写)。我还有一个用 phantom.js 制作并监听端口 8080 的第二个本地服务器:
var server, service;
server = require('webserver').create();
service = server.listen(8080, function (request, response) {
response.statusCode = 200;
response.write('<html><body>Hello!</body></html>');
response.close();
});
现在我想从我的应用程序向虚拟服务器发出 Ajax 请求:
Ext.Ajax.request({
url: 'http://localhost:8080',
method: 'GET',
success: function(response){
console.log('RESPONSE: ', response);
},
filure: function(response){
console.log('failure: ', response);
}
});
但是当运行这个脚本时我得到:
“NetworkError: 400 Bad Request - http://localhost:8080/?_dc=1336648497292”
在控制台中。此操作是否违反同源策略?或者是别的什么 ?转到 localhost:8080 显示正确的响应,因此服务器运行正常。
最佳答案
你的 html 也在 localhost:8080 上?如果不是(不同的端口 => 不同的主机)那么你有跨域 ajax 问题。
关于javascript - 从本地 js 脚本对本地 Phantom.js 服务器的 Ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10533172/