位一个JavaScript新手在这里的 -JavaScript错误试图解雇简单的XMLHttpRequest时(GET)
我射击的JavaScript代码,这个基本的位从我的网站作为一个测试:
var req = new XMLHttpRequest();
req.open('GET', 'http://www.google.co.uk/', false);
req.send();
if (req.status == 200) {
alert(req.responseText);
}
和我不断收到以下错误:
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://localhost/testEx3/Default.aspx :: SendRequest :: line 402" data: no]
有没有人知道我在做什么错在这里?
UPDATE:
OK - 所以什么我actaully试图做的是一个POST请求,我在我的本地开发机器上发布的Web服务 - 我居然也得到了同样的错误如上 - 这就是为什么为了简单,我举了这个例子。现在看起来“同源策略”已经发挥作用 - 所以现在我已经发布了带有URI的开始部分的web服务,作为http://localhost/
而不是http://tempuri.org/
。
现在我得到一个500错误。有什么我在标题中缺少的东西?
var request = new XMLHttpRequest();
request.open("POST", "http://localhost/ApplicationServices.asmx?op=AddressSearch", false, "", "");
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
request.send(x, y, buffer);
if (request.status == 200) {
alert("Success");
}
else {
alert("Failure: " + request.status);
}
删除了不再起作用的同源标签。 – ajm 2010-08-09 17:39:37