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

javascript - NS_ERROR_FAILURE : Failure in Firefox - Stack Overflow

programmeradmin3浏览0评论

I'm using javascript's XMLHttpRequest object to send a request to another page (not on the same server or domainname ) I get a ns_error_failure error in firefox, but the Javascript works in Google Chrome, after searching online it seems to be because of firefox's XSS policy. Cross-Domain requests are not allowed.

Is there anyway to work around this and make the JS run in both chrome and Firefox?


Please feel free to ask for additional details you feel are needed!


Here's the code that I was using.

"use strict";

function showFixed(username)
{
    console.log("Entered script");

    var url = ''
        + '?quicksearch='
        + encodeURIComponent('FIXED @'+username);
    displayBug(url);
}

function showPending(username)
{
    console.log("Entered script");

    var url = ''
        + '?quicksearch='
        + encodeURIComponent('@'+username);
    displayBug(url);
}

function showCC(username)
{
    console.log("Entered script");

    var url = ''
        + '?quicksearch='
        + encodeURIComponent('cc:'+username);
    displayBug(url);
}

function displayBug(url)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET",url,false);
    xmlhttp.send();
    var text = xmlhttp.responseText;

    var json = JSON.parse(text);

    for(var i=0;i<json.bugs.length;i++)
    {
        var tempRow = document.createElement('tr');

        var tempId = document.createElement('td');
        tempId.innerHTML = '<a href=\'.cgi?id=' + json.bugs[i].id + '\'>'+ json.bugs[i].id + '</a>';
        var tempCreator = document.createElement('td');
        tempCreator.innerHTML = json.bugs[i].creator.real_name;
        var tempShortDesc = document.createElement('td');
        tempShortDesc.innerHTML = json.bugs[i].summary;
        var tempComponent = document.createElement('td');
        tempComponent.innerHTML = json.bugs[i]ponent;
        var tempAssignee = document.createElement('td');
        tempAssignee.innerHTML = json.bugs[i].assigned_to.real_name;
        var tempWhiteBoard = document.createElement('td');
        tempWhiteBoard.innerHTML = json.bugs[i].whiteboard;
        var tempBugStatus = document.createElement('td');
        tempBugStatus.innerHTML = json.bugs[i].status;
        var tempResolution = document.createElement('td');
        tempResolution.innerHTML = json.bugs[i].resolution;
        var tempLastChange = document.createElement('td');
        tempLastChange.innerHTML = json.bugs[i].last_change_time;

        tempRow.appendChild(tempId);
        tempRow.appendChild(tempAssignee);
        tempRow.appendChild(tempCreator);
        tempRow.appendChild(tempBugStatus);
        tempRow.appendChild(tempShortDesc);
        tempRow.appendChild(tempLastChange);
        document.getElementById('bugs-table-tbody').appendChild(tempRow);
    }

    document.getElementById('main').innerHTML = '';
}

function wrapper()
{
    var waitString = "Please wait while bug list is loaded..."
    document.getElementById('main').innerHTML = waitString;

I'm using javascript's XMLHttpRequest object to send a request to another page (not on the same server or domainname ) I get a ns_error_failure error in firefox, but the Javascript works in Google Chrome, after searching online it seems to be because of firefox's XSS policy. Cross-Domain requests are not allowed.

Is there anyway to work around this and make the JS run in both chrome and Firefox?


Please feel free to ask for additional details you feel are needed!


Here's the code that I was using.

"use strict";

function showFixed(username)
{
    console.log("Entered script");

    var url = 'https://api-dev.bugzilla.mozilla/latest/bug'
        + '?quicksearch='
        + encodeURIComponent('FIXED @'+username);
    displayBug(url);
}

function showPending(username)
{
    console.log("Entered script");

    var url = 'https://api-dev.bugzilla.mozilla/latest/bug'
        + '?quicksearch='
        + encodeURIComponent('@'+username);
    displayBug(url);
}

function showCC(username)
{
    console.log("Entered script");

    var url = 'https://api-dev.bugzilla.mozilla/latest/bug'
        + '?quicksearch='
        + encodeURIComponent('cc:'+username);
    displayBug(url);
}

function displayBug(url)
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET",url,false);
    xmlhttp.send();
    var text = xmlhttp.responseText;

    var json = JSON.parse(text);

    for(var i=0;i<json.bugs.length;i++)
    {
        var tempRow = document.createElement('tr');

        var tempId = document.createElement('td');
        tempId.innerHTML = '<a href=\'https://bugzilla.mozilla/show_bug.cgi?id=' + json.bugs[i].id + '\'>'+ json.bugs[i].id + '</a>';
        var tempCreator = document.createElement('td');
        tempCreator.innerHTML = json.bugs[i].creator.real_name;
        var tempShortDesc = document.createElement('td');
        tempShortDesc.innerHTML = json.bugs[i].summary;
        var tempComponent = document.createElement('td');
        tempComponent.innerHTML = json.bugs[i].ponent;
        var tempAssignee = document.createElement('td');
        tempAssignee.innerHTML = json.bugs[i].assigned_to.real_name;
        var tempWhiteBoard = document.createElement('td');
        tempWhiteBoard.innerHTML = json.bugs[i].whiteboard;
        var tempBugStatus = document.createElement('td');
        tempBugStatus.innerHTML = json.bugs[i].status;
        var tempResolution = document.createElement('td');
        tempResolution.innerHTML = json.bugs[i].resolution;
        var tempLastChange = document.createElement('td');
        tempLastChange.innerHTML = json.bugs[i].last_change_time;

        tempRow.appendChild(tempId);
        tempRow.appendChild(tempAssignee);
        tempRow.appendChild(tempCreator);
        tempRow.appendChild(tempBugStatus);
        tempRow.appendChild(tempShortDesc);
        tempRow.appendChild(tempLastChange);
        document.getElementById('bugs-table-tbody').appendChild(tempRow);
    }

    document.getElementById('main').innerHTML = '';
}

function wrapper()
{
    var waitString = "Please wait while bug list is loaded..."
    document.getElementById('main').innerHTML = waitString;
Share Improve this question edited May 19, 2013 at 18:33 ffledgling asked Mar 15, 2013 at 21:02 ffledglingffledgling 12.2k8 gold badges52 silver badges70 bronze badges 8
  • How are you able to run a XMLHttpRequest cross-domain? Never loads for me in Chrome... – Qantas 94 Heavy Commented May 17, 2013 at 10:24
  • Well ... I don't know why it works, but it does. I'm sending requests to the bugzilla-api. You can take a look at the code if you like. I tested it on Chrome 26, also worked on older chromes and chromiums. – ffledgling Commented May 18, 2013 at 22:45
  • That'd be interesting to see, thanks. – Qantas 94 Heavy Commented May 19, 2013 at 5:44
  • @Qantas94Heavy See edit. You probably just want to look at one of the show* functions and the initial bits of the displaybug function – ffledgling Commented May 19, 2013 at 18:36
  • Did you try xmlhttprequest.send( null ) instead of xmlhttprequest.send( ) ? I remember I had this error message once because of this. – rplantiko Commented Jun 5, 2013 at 20:00
 |  Show 3 more ments

1 Answer 1

Reset to default 1

If you are able to use jQuery, I would suggest having a look at JSONP (http://www.jquery4u./json/jsonp-examples/) this effectively allows crossdomain ajax.

发布评论

评论列表(0)

  1. 暂无评论