Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try

$(document).ready(function() {
    $("#form").submit(function(){
        $.post("process.php", $("#form").serialize());    
    });
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...