2

With a firefox addon (javascript) I'm trying to send a POST request to a server to get a session ID back, but none of conventional methods seem to work, I already tried xmlhttprequest and getting it with forms isn't possible because it's internal code. Is there a way to get this working, maybe even with the addon SDK?

References to my tries:

Javascript sending data via POST in firefox addon

HTTP POST in javascript in Firefox Extension

Community
  • 1
  • 1
Pinetrax
  • 35
  • 1
  • 6
  • This solution here also has a XHR but for non-sdk (which can also be used in sdk) http://stackoverflow.com/questions/2471666/ajax-in-firefox-plugin/25514239#25514239 – Noitidart Apr 13 '15 at 14:22

1 Answers1

5

With the new Addon SDK you should use the new Request API instead of XMLHttpRequest. The new Interface is a lot easier to use, too.

Here is a quick example:

// make sure this gets executed BEFORE making the Request
var Request = require("sdk/request").Request;

Request({
  url: "http://example.com/hello-world.php",
  content: { hello: 'world' },
  onComplete: function (response) {
    console.log( response.text );
  }
}).post();

I suggest you may have a look at this MDN Tutorial: Getting started

tim-we
  • 1,219
  • 10
  • 16