2012-05-10 66 views
1

我已经设置了一个运行本地Web服务器(用ExtJs编写)的Apache服务器。我也phantom.js提出并监听8080端口塞康本地服务器:Ajax从本地js脚本调用本地Phantom.js服务器

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显示正确的响应,所以服务器正常运行。

+0

不同的端口将是一个与原点不同的域。 –

+0

*此操作是否违反相同的原产地规定?*是*或者是其他内容?*是的。服务器正在报告400错误请求错误。 – Quentin

+0

确定'错误请求'错误是否来自跨域问题? –

回答

2

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

+0

该死的,这么想:/不,html是在80端口。 –

+0

尝试如果这有助于:http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy – Gavriel

0

Ajax不适用于File protocals!它只适用于HTTP或HTTP。我找到了一个关于udemy的课程,导师说ajax不会在file:d://(path)protocals上工作。于是他将文件转移到网络服务器上,然后在ajax上解释他的主题。

希望这有助于!