Cross-origin XHR timeout in Firefox OS

243 views Asked by At

I'm trying to implement the Simple Push API and I'm trying to do a cross-origin XMLHttpRequest. I'm doing a test:

function sendEndPoint() {
    var MAXIMUM_WAITING_TIME = 6000;

    if (!window.XMLHttpRequest) {
        addDebugMessage("XMLHttpRequest not supported.");
    } else {
        addDebugMessage("XMLHttpRequest supported!");
        var xhReq = new XMLHttpRequest({
            mozAnon: true,
            mozSystem: true
        });
        xhReq.open("get", "http://192.168.1.69/ping/index.php", true); // Server stuck in a loop.

        //Request timeout.
        var requestTimer = setTimeout(function () {
            xhReq.abort();
            addDebugMessage("Error timeout: time was " + MAXIMUM_WAITING_TIME);
        }, MAXIMUM_WAITING_TIME);

        //It's ready.
        xhReq.onreadystatechange = function () {
            if (xhReq.readyState != 4) {
                return;
            }
            clearTimeout(requestTimer);
            if (xhReq.status != 200) {
                addDebugMessage("Error in request.");
                return;
            }

            var serverResponse = xhReq.responseText;
        };

    }
}

Where http:// 192 . 168. 1. 69/ping/index.php it's just a hello world message and I can reach it using the web browser of my Firefox OS device.

I'm getting always a timeout error, it doesn't matter how much I wait, why?

Thanks.

2

There are 2 answers

0
Cod1ngFree On BEST ANSWER

I was missing xhr.send() and I forgot to set the systemXHR permission:

"permissions": {
    "push": {
        "description": "Required for being updated."
    },
    "systemXHR" : {}
}
0
msaad On

Jut to increment your self-answer, more information on XHR Requests and methods can be found at Mozilla Developer Network- XHR