1

I'm a newbie trying to do a simple HTTP post in JS within a Firefox extension..

This isn't passing through the parameters:

var params = "a=1&b=2&c=3"
req.open('POST', 'http://www.mywebsite.com/');
req.send(params);

Any ideas on what I'm doing wrong? Thanks.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
hemal
  • 193
  • 2
  • 8

3 Answers3

1

Make sure you've included the header to tell the server what type of request body you're sending it:

req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

(Assuming req is an XMLHttpRequest created earlier in the code.)

bobince
  • 528,062
  • 107
  • 651
  • 834
0

Make sure you add

var req = new XMLHttpRequest(); 
nebkat
  • 8,445
  • 9
  • 41
  • 60
-1

You don't need an extension, plain JavaScript can do this:

Asynchronous cross-domain POST request via JavaScript?

Community
  • 1
  • 1
Luca Matteis
  • 29,161
  • 19
  • 114
  • 169
  • He is specifically looking to do this _within_ a Firefox extension. Whether or not an extension is necessary is irrelevant. – Kyle Jun 01 '11 at 18:11