NS_ERROR_FAILURE: сбой в Firefox - программирование
Подтвердить что ты не робот

NS_ERROR_FAILURE: сбой в Firefox

Я использую javascript объект XMLHttpRequest для отправки запроса на другую страницу (не на том же сервере или в домене). Я получаю ошибку ns_error_failure в firefox, но Javascript работает в Google Chrome, после поиска в Интернете это похоже на то, что политики Firefox XSS. Междоменные запросы не разрешены.

Есть ли способ обойти это и сделать запуск JS как в Chrome, так и в Firefox?


Пожалуйста, не стесняйтесь спрашивать дополнительную информацию, которую вы считаете нужным!


Вот код, который я использовал.

"use strict";

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

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

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

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

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

    var url = 'https://api-dev.bugzilla.mozilla.org/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.org/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].component;
        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;
4b9b3361

Ответ 1

Если вы можете использовать jQuery, я бы предложил посмотреть на JSONP (http://www.jquery4u.com/json/jsonp-examples/), это эффективно позволяет использовать crossdomain ajax.