HTTP POST in javascript in Firefox extension

I am a newbie trying to make simple HTTP mail in JS in the Firefox extension ..

This does not go 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.

+1
source share
3 answers

Make sure you include the header to tell the server what type of request body you are sending it to:

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

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

+1
source

Make sure you add

 var req = new XMLHttpRequest(); 
0
source

You do not need an extension, simple JavaScript can do this:

Asynchronous POST request request via JavaScript?

-1
source

Source: https://habr.com/ru/post/1332835/


All Articles