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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 04:53:39  来源:igfitidea点击:

NS_Error_Failure on Javascript POST

javascript

提问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_failureexception (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

This error can be seen if there are,

如果有,可以看到这个错误,

  1. URL not found
  2. There is error in your server code or called URL.
  1. 未找到网址
  2. 您的服务器代码或调用的 URL 中存在错误。

There is not any visible problem in code you shared. Please refer this link

您共享的代码中没有任何可见的问题。请参考这个链接

回答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>