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.
I was missing xhr.send() and I forgot to set the systemXHR permission:
"permissions": {
"push": {
"description": "Required for being updated."
},
"systemXHR" : {}
}