Javascript sending data via POST in firefox addon

前端 未结 3 1468
囚心锁ツ
囚心锁ツ 2021-01-13 20:03

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 us

相关标签:
3条回答
  • 2021-01-13 20:34

    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.

    0 讨论(0)
  • 2021-01-13 20:40

    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.

    0 讨论(0)
  • 2021-01-13 20:46

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

    0 讨论(0)
提交回复
热议问题