AJAX结合form表单post提交

<!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>
<title>AJAX结合form表单post提交</title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" 

src="http://www.wmdfw.com/h_ui/jquery.js"></script>

<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("div").text($("form").serialize());
    alert($("form").serialize());
    var data=$("form").serialize();
    $.ajax({
    url: 'x.php',
    type: 'post',
    data:data,
    dataType: 'html',
    timeout: 1000,
    error: function(){
     alert('Sorry!注册错误,请联系管理员!');
    },
    success: function(html){
     //$('#text').html(html);
     alert('注册成功!');
     window.location.href='http://www.wmdfw.com/';
    }
    });
  });
});
</script>
</head>
<body>
<form action="">
用户名: <input type="text" id="name" name="name" value="zhangsan" /><br />
密  码: <input type="text" id="pwd" name="pwd" value="123456" /><br />
性  别: <input type="text" id="sex" name="sex" value="0" /><br />
</form>
<button>序列化表单提交</button>
<div></div>
</body>
</html>

 

posted @ 2015-11-17 18:28  钢锅  阅读(793)  评论(0编辑  收藏  举报