一、HTML页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>表单提交</title> <mce:script type="text/javascript" src="jquery-1.4.js" mce_src="jquery-1.4.js"></mce:script> <mce:script type="text/javascript"><!-- $(function(){ //init 初始化 function init(){ $('input[name=post]').bind('click',function(){ //当点击name为post的input按钮时触发post函数 post(); }); } init(); function post(){ if($('input[name=title]').val() == ''){ $('#titleT').html("请填写标题"); return false; } if($('textarea[name=content]').val() == ''){ $('#contentT').html("请填写留言内容"); return false; } var sendObj={ url:'/post.php', async:false, type:'post', data:$('input').serialize() + '&' + $('textarea').serialize(), // 序列化所有input 和textarea success:function(data){//alert(data); if(data == 'yes'){ alert("表单提交成功"); }else{ alert("失败"); } } }; $.ajax(sendObj); } }) // --></mce:script> </head> <body> <input type="text" name="title" /> <textarea name="content" id="content"> <input type="button" name="post" value="AJAX提交"> </body> </html> 二、post.php页面 <?php $title = $_POST[title]; $content=$_POST[content]; $sql = "INSERT INTO table ()value()"; if(mysql_query($sql)){ echo "yes"; }else{ echo "false"; } ?>