最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

NS_Error_Failure on Javascript POST - Stack Overflow

programmeradmin2浏览0评论

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?

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]

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?

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]
Share Improve this question edited Jan 22, 2013 at 12:46 sohel khalifa 5,5783 gold badges36 silver badges46 bronze badges asked Jun 26, 2012 at 6:56 Ben CameronBen Cameron 4,4136 gold badges54 silver badges78 bronze badges 3
  • This question may help – Mitya Commented Jun 26, 2012 at 7:02
  • 1 seen something similar with Prototype.js overriding the setRequestHeader function. – BigMike Commented Jun 26, 2012 at 7:06
  • 2 @Ben Cameron: I think this problem is down to illegal cross site requests. Did you solve your problem with UmeshA's solution? – Gruber Commented Dec 14, 2012 at 9:57
Add a comment  | 

2 Answers 2

Reset to default 8

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 id="iframe_execute" name="iframe_execute" frameborder="1" height="400" width="400"></iframe>

This error can be seen if there are,

  1. URL not found
  2. There is error in your server code or called URL.

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

发布评论

评论列表(0)

  1. 暂无评论