Javascript sending data via POST in firefox addon

I have a mysql database with php form. Usually people use the php form on my website to add mysql to the database. I am creating a firefox addon to allow them to use the form without visiting the site directly to add data to the mysql database. Now I'm stuck ...

I have form data that I want to add to the mysql database, but how can I submit it to the mysql database from the addon? What is the best way to do this? Will you submit it to php form first or is there a direct way? Is it possible to go straight to mysql? Firefox addon encoded in javascript.

Thanks!

+4
source share
3 answers

Jan Hancic is right: the best way is to use XMLHttpRequest.

Here is an example:

var xhr = new XMLHttpRequest(); xhr.open("post", "http://ex.ample.com/file.php", true); xhr.onreadystatechange = function() { if(this.readyState == 4) { // Do something with this.responseText } } xhr.send("var1=val1&var2=val2"); 

There are many guides and links on the Internet about AJAX and the xhr object.

+1
source

Ajax seems to be the way to go. This post may be useful for you: HTTP POST in javascript in Firefox Extension .

+1
source

Use Ajax to send data, but do not use xmlHttpRequest directly in your code.

Use a popular javascript library like jquery to send data to the server.

Edit : Removed unnecessary parts about browser compatibility.

-1
source

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


All Articles