Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NS_Error_Failure on Javascript POST

Tags:

javascript

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]
like image 614
Ben Cameron Avatar asked Jun 26 '12 06:06

Ben Cameron


2 Answers

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>
like image 186
XMedia Software Avatar answered Nov 03 '22 06:11

XMedia Software


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

like image 4
Umesh Aawte Avatar answered Nov 03 '22 05:11

Umesh Aawte