Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FF extension - getting xmlhttp.status==0

I'm writing an extension for Firefox and it is using page-mod module to run a JavaScript file containing:

function handleServerResponse() {

   if (xmlHttp.readyState == 4) {
     if(xmlHttp.status == 200) {
        //some code
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}

var xmlHttp = new XMLHttpRequest();
var txtname = document.getElementById("txtname");
xmlHttp.open("POST","http://localhost:8080/Jelly/GetStuff",true);
xmlHttp.onreadystatechange  = handleServerResponse;
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send("url=" + document.URL);

i'm keep getting xmlhttp.status==0 and not 200, even if instead of localhost I use the IP address. Any ideas?

like image 656
alon Avatar asked Jan 21 '26 17:01

alon


1 Answers

Content script code can't do cross-domain requests - try using the Request module instead:

https://addons.mozilla.org/en-US/developers/docs/sdk/1.1/packages/addon-kit/docs/request.html

Instead of writing the code in a separate script and injecting it into a page using a page-mod, you can implement the request in the main.js script in your add-on.

like image 106
therealjeffg Avatar answered Jan 23 '26 21:01

therealjeffg