欢迎光临
感谢一路有你

Ajax-form表单禁止跳转

如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
 

 

onsubmit=”return false”//在form属性中加入此属性,禁止跳转

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>form表单提交ajax</title>
    <script src="../../../../jquery-1.8.3.min.js"></script>
</head>
<body>
<form id="form1" method="post" onsubmit="return false">
    姓名:<input type="text" name="name" >
    密码:<input type="text" name="pwd" >
    <input type="submit" value="提交" id="tj">
</form>

</body>
</html>
<script>
    $(function(){
        $("#tj").click( function (){
            var data = $('#form1 input').serializeArray();//返回json对象
            $.ajax({
                type:'post',
                url:'./2.php',
                data:data,
                success:function(data){
                    alert(data);
                }
            })
        })
        
    })

</script>

 

 

 

赞(0) 打赏
未经允许不得转载:王明昌博客 » Ajax-form表单禁止跳转
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏