2
votes

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

1
This solution here also has a XHR but for non-sdk (which can also be used in sdk) stackoverflow.com/questions/2471666/ajax-in-firefox-plugin/… - Noitidart

1 Answers

5
votes

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