提交表单用ajax判断登录正确再跳转页面的方法二

来源:互联网 发布:objective-c和java 编辑:程序博客网 时间:2024/05/11 01:48

用submit()方法,注意.btn这个input元素的type不能设置为submit,而是要设置为button


区别:

利用submit()跳转页面,则form的action要设置为某个具体的页面,且点击的按钮的type是button

利用location.href跳转页面,则form的action为空,在location.href里指定具体页面,点击的按钮的type是submit



<!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></head><body><form id="myform" action="member.html" method="post"><input name="" type="text" /><input name="" type="button" id="btn" value="按钮"/></form><script type="text/javascript" src="js/jquery-1.12.3.js"></script><script type="text/javascript">$(function(){$("#btn").click(function(){$.ajax({type: "POST",url: "more.json",dataType: "json",        success: function(json){if(json.success==1){$("#myform").submit();}else{return false;}},error: function() {            // view("异常!");            alert("异常!");       }  });});});</script></body></html>

more.json

{    "msg": "登录成功",    "success": 1}



0 0
原创粉丝点击