javascript - 从本地 js 脚本对本地 Phantom.js 服务器的 Ajax 调用

标签 javascript ajax apache extjs phantomjs

我已经设置了一个本地运行的 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/

相关文章:

javascript - 如何在元素未加载时注册元素 onload?

php - 如何限制仅从我网站内的页面访问某些 PHP 页面?

javascript - 无法在 jquery getjson 函数中设置变量?

linux - Apache 和 Varnish http/https

javascript - jQuery.addClass() 不工作

javascript - 使 Logo 在滚动时缩小到导航栏中

javascript - 删除尾随零到小数点后 2 位

javascript - 如何在 ajax 在 Angular Js 上完成之前加载 View ?

linux - Apache Total 通过 vhost 重定向到 https 需要一个位置

java - 将对象添加到对象池