Home > Backend Development > PHP Tutorial > ajax?表单的验证

ajax?表单的验证

WBOY
Release: 2016-06-23 13:28:00
Original
945 people have browsed it

将表单的数据通过ajax传替的对应的XXX.php里验证,再返回验证结果
哪位大哥能分享这段的代码


回复讨论(解决方案)

$.ajax({   type:'POST', //提交方式 POST 更安全   url:"www.xx.com/validate.php", //后端验证文件地址   data:{user_name:user,password:pwd},//验证参数   cache:false, //是否缓存   dataType:json, //返回数据类型是JSON格式   success:function(json){        if(json.status == 1){           //处理用户名不存在        }else if((json.status==2){           //处理其他情况      }   },   error:function(json){     console.log("网络错误!");   }});
Copy after login

$user_name = $POST['user_name'];$password = $POST['password'];if($user_name == ""){    echo "{status:1}";}else if($user_name != "zhangshan"){    echo "{status:2}";}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template