【发布时间】:2011-03-31 09:51:19
【问题描述】:
这是我的 javascript sn-p:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
...
}
}
}
var url = 'http://localhost:3000/questions/1';
xhr.open('GET', url, true);
xhr.send();
this.status 始终为 0,this.responseText 始终为 ""
如果我直接从浏览器 ping url 'http://localhost:3000/questions/1',我会得到正确的 html。
仅供参考,我正在 ping 我的机器上运行的 Rails 服务器。
【问题讨论】:
-
您从哪个域调用它?也是
http://localhost:3000吗? -
确保主机:端口与same origin policy相同
标签: javascript ruby-on-rails xmlhttprequest