Javascript在firefox插件中通过POST发送数据 [英] Javascript sending data via POST in firefox addon
问题描述
我有我要添加到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屋!