0

I have below code to send string from Firefox addon to MySQL. It works if I run by console i.e. I get data in MySQL. But when I add it to the extension it doesn't work. Even the line above of this script in the extension (which write text to a text file) runs i.e. write to that text file.

I referred below links

XMlHttpRequest is not working in Firefox extension

How to use jQuery in Firefox Extension

jQuery in Firefox extension

jQuery in firefox extension

Adding Jquery and Other JS libraries to Firefox Extension

var http = new XMLHttpRequest();
http.open("GET", "http://localhost/todayreport/ajax.php?firefoxaddondata=data", true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Connection", "close");
http.send();
Community
  • 1
  • 1
Dhay
  • 585
  • 7
  • 29
  • What is your context? Are you using addon sdk? or classic bootstrap/jsm? Or worker? – Noitidart Sep 26 '15 at 17:16
  • Noitidart, Mine is xul addon. Sorry I forget to mention it. – Dhay Sep 28 '15 at 07:15
  • Then instead of `new XMLHttpRequest()` do `createInstance` so: `Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);` – Noitidart Sep 28 '15 at 10:34
  • I tried adding `const {Cc, Ci, Cu, components} = require("chrome");` and modified `new XMLHttpRequest()` to `Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpReque‌​st);`, But is this the right way? shouldn't we convert it to bootstrap? I got this question because the above changes have no effect. Actually I try this thing because I couldn't convert the addin for this code from xul to restartless as my previous question http://stackoverflow.com/questions/32783930/firefox-addon-could-not-convert-to-bootstrap – Dhay Sep 29 '15 at 05:19

1 Answers1

0

in my bootstrap extension i added this at the top

const XMLHttpRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest");

then you can use normally

var xhttp = new XMLHttpRequest();
masadwin
  • 422
  • 2
  • 5
  • 11