开发者

jQuery form processing and posting

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());    
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜