There is a XMLHttpRequest in the content script of my Firefox WebExtensions add on. Q: why is the status of this request is always 0?
This is the JavaScript code making the request:
var query = "http://api.wolframalpha.com/v2/query?appid=[MY-APP-ID]&includepodid=Comparison&scanner=Unit&format=plaintext&input=1%20lm";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
console.log("onreadystatechange");
console.log(this);
if (this.readyState == 4 && this.status == 200)
{
onSuccess(this.responseText);
}
};
xhttp.open("GET", query, true);
xhttp.send();
If I print out the results of the request for each onreadystatechange call, I get:
XMLHttpRequest { onreadystatechange: makeWolframRequest/xhttp.onreadystatechange(),
readyState: 1, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload,
responseURL: "", status: 0, statusText: "", responseType: "", response: "" }
XMLHttpRequest { onreadystatechange: makeWolframRequest/xhttp.onreadystatechange(),
readyState: 2, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload,
responseURL: "", status: 0, statusText: "", responseType: "", response: "" }
XMLHttpRequest { onreadystatechange: makeWolframRequest/xhttp.onreadystatechange(),
readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload,
responseURL: "", status: 0, statusText: "", responseType: "", response: "" }
Things I checked:
- Content scripts should be able to make cross-domain requests according to the WebExtensions documentation.
- Making a request to "https://api.wolframalpha.com/" instead of "http://api.wolframalpha.com/".