1

我已经设置了一个本地运行的 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 显示正确的响应,因此服务器运行正常。

4

2 回答 2

2

你的 html 也在 localhost:8080 上?如果不是(不同的端口 => 不同的主机),那么你有跨域 ajax 问题。

于 2012-05-10T11:45:19.883 回答
0

Ajax 不适用于文件协议!它仅适用于 HTTP 或 HTTP 。我找到了关于 udemy 的课程,导师说 ajax 不适用于 file:d://(path) protocals。所以他把他的文件转移到网络服务器上,然后他解释了他关于 ajax 的话题。

希望这可以帮助!

于 2016-01-05T17:12:07.533 回答