jQuery表单处理和发布 [英] jQuery form processing and posting
问题描述
我真的想用jQuery来找到某个地方,但我无法让它处理表单。这里是我的(测试)代码:
< form id =form>
< input type =textname =abc/>
< input type =textname =def/>
< input type =textname =ghi/>
< input type =submitname =tryid =try/>
< / form>
和jQuery:
$(document).ready(function($){
$(#try)。click(function(){
$ .post(process.php ,$(#form)。serialize());
});
});
作为一个简单的测试,我在process.php上有这个,如果我访问进程PHP直接它工作
mysql_query(INSERT INTO testit(tryit)VALUES('1'));
如果我再尝试
$ tryit = $ _POST ['abc'];
mysql_query(INSERT INTO testit(tryit)VALUES($ tryit));
即访问post变量abc什么也没有发生
是的,我连接到DB
为什么jQuery不能进入页面process.php?
<我可以在浏览器中看到这个序列化。
pre $ testc.php abc = q345& def = 345& ghi = 2345& try = Submit + Query
我真正想要做的是将表单变量POST到数据库表,为什么我不能得到它的工作?或者如上所述或者试图发布变量?
试试
< $($)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' .php,$(#form)。serialize());
});
});
I am really trying to get somewhere with jQuery, but I just cannot get it to process forms. Here is my (test) code:
<form id="form" >
<input type="text" name="abc" />
<input type="text" name="def"/>
<input type="text" name="ghi"/>
<input type="submit" name="try" id="try" />
</form>
and the jQuery:
$(document).ready(function($) {
$("#try").click(function() {
$.post("process.php", $("#form").serialize());
});
});
As a simple test I am have this on process.php and if I access process php direct it works
mysql_query("INSERT INTO testit (tryit) VALUES ('1')");
if I then try
$tryit = $_POST['abc'];
mysql_query("INSERT INTO testit (tryit) VALUES ($tryit)");
i.e accessing the post variable abc nothing happens
Yes I do connect to the DB
Why does the jQuery not go to the page process.php?
The serialization works as I can see this in the browser
testit.php?abc=q345&def=345&ghi=2345&try=Submit+Query
What I really want to do is POST the form variables into the DB table, why can I not get it to work? either as above or by trying to post the variables?
Try
$(document).ready(function() {
$("#form").submit(function(){
$.post("process.php", $("#form").serialize());
});
});
这篇关于jQuery表单处理和发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!