Javascript POST 上的 NS_Error_Failure
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11202153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NS_Error_Failure on Javascript POST
提问by Ben Cameron
I am having trouble with some javascript. The code snippet below creates a simple post request however it always throws an NS_Error_failure
exception (details at the bottom of the page). Can anyone tell me whats wrong with this code?
我在使用某些 javascript 时遇到问题。下面的代码片段创建了一个简单的发布请求,但它总是抛出NS_Error_failure
异常(页面底部的详细信息)。谁能告诉我这段代码有什么问题?
window.onload = function () {
alert('0');
try {
var url = "Some URL";
var request = CreateHttpRequest();
if (request) {
alert('1');
request.open("POST", url, false);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
alert('2');
request.send('');
alert('3');
}
}
catch (err) {
alert(err);
}
}
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)"
nsresult: "0x80004005 (NS_ERROR_FAILURE)"
location: "JS frame :: file:///C:/Users/Ben/Desktop/test.html :: <TOP_LEVEL> :: line 44" data: no]
采纳答案by Umesh Aawte
回答by XMaster
I found the same problem and when I was sending all to an iframe, the problem solved when I add the "name" to the tag, maybe the target is not accesible by your script
我发现了同样的问题,当我将所有内容发送到 iframe 时,当我将“名称”添加到标签时问题解决了,也许目标无法被您的脚本访问
<iframe id="iframe_execute" name="iframe_execute" frameborder="1" height="400" width="400"></iframe>