Reputation: 709
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:
Upvotes: 3
Views: 771
Reputation: 709
In this case it was a CORS issue. I had to add this secret sauce to my manifest.json
file:
"permissions": [
"http://api.wolframalpha.com/*"
]
More information here: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/permissions
Much thanks to @adeneo for insisting I keep looking at CORS issues.
Upvotes: 1