Javascript在firefox插件中通过POST发送数据 [英] Javascript sending data via POST in firefox addon

查看:326
本文介绍了Javascript在firefox插件中通过POST发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MySQL数据库,一个PHP表单。通常,人们使用我的网站上的PHP表单添加到MySQL数据库。我一直在建立一个Firefox插件,让他们不用直接访问这个网站就可以把数据添加到mysql数据库中。现在我被卡住了...

我有我要添加到mysql数据库的表单数据,但是我怎样才能从插件发送到mysql数据库?什么是最好的方法来做到这一点?你会把它发送到PHP的形式或有直接的方式?可以直接去mysql吗? firefox插件是用javascript编码的。



谢谢!

解决方案

JanHančič是正确的:最好的方法是使用XMLHttpRequest。

下面是一个例子:

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

网上有很多关于AJAX和xhr对象的教程和参考资料。


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!

解决方案

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.

这篇关于Javascript在firefox插件中通过POST发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆