4

I have a mysql database, with a php form. Normally, people use the php form on my website to add to the mysql database. I have been building a firefox addon to let them use the form without visiting the site directly to add data to the mysql database. Now I am stuck...

I have the form data I want to add to the mysql database, but how can I send it to the mysql database from the addon? What's the best way to do this? Would you send it to the php form first or is there a direct way? Is it possible to go straight to mysql? The firefox addon is coded in javascript.

Thanks!

David19801
  • 11,214
  • 25
  • 84
  • 127
  • I don't know anything about FF's extensions. But I'm pretty sure you can make a XHR (AJAX) request somehow. Would that work? – Jan Hančič Dec 20 '10 at 22:14

3 Answers3

1

It sounds like Ajax would be the way to go. This post may be helpful to you: HTTP POST in javascript in Firefox Extension.

Community
  • 1
  • 1
Chocula
  • 1,946
  • 1
  • 16
  • 21
1

Jan Hančič is right : the best way is to use XMLHttpRequest.

Here's 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 plenty of tutorials and references on the web about AJAX and the xhr object.

Pik'
  • 6,819
  • 1
  • 28
  • 24
  • "There are plenty of tutorials and references on the web about AJAX and the xhr object." This being the official Mozilla one: https://developer.mozilla.org/en/xmlhttprequest – Tyler Dec 21 '10 at 05:24
0

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 irrelevant parts about browser compatibility.

Mohsen
  • 393
  • 7
  • 9
  • 1
    But he is building an addon for firefox, so compatibility shouldn't be an issue – Dan Dec 20 '10 at 22:42
  • You still might want to use jQuery for other reasons, of course, but yes, compatibility is not one of them in this case. – Tyler Dec 21 '10 at 05:23