[英]Jquery validate plugin, How to check if PHP file returns an error or ok to redirect user to homepage/dashbord
First off this is my first question on here so I am sorry for anything I may do wrong. 首先,这是我在这里的第一个问题,因此对我可能做错的任何事情感到抱歉。 But.... 但....
My question is how do I take whats sent back from my PHP file to see if username/password combo exists in the database. 我的问题是如何处理从PHP文件发回的内容,以查看数据库中是否存在用户名/密码组合。 My PHP either returns true or false depending on the submitting. 我的PHP根据提交的结果返回true或false。 That works fine I just do not know how to use the returned data and compare it to either true or false. 那很好,我只是不知道如何使用返回的数据并将其与true或false进行比较。
////This is my Jquery of my form which works fine validating and sending data to PHP.
$("#frmsignin").validate({
rules:{
passin:"required",
emailin:{
required:true,
email:true
}
},
messages:{
passin:"Please enter YOUR password",
emailin:{
required:"Please enter YOUR email address",
email:"Please enter a VALID email address"
}
},
submitHandler: function(form) {
$.post('sign_in.php',
$("#frmsignin").serialize(),
function(data){$('#results').html(data)});
}
});
Right Now I just have my PHP file printing back true/ false just to get the error message or redirection to occur if user signs in correctly. 现在,我只是将我的PHP文件打印回true / false,只是为了获得错误消息或如果用户正确登录就会发生重定向。
Simple: Return a json data structure: 简单:返回json数据结构:
<php
$data = '... the stuff you want to return';
if ($data == '') {
// oops something blew up
$json = array('success' => false);
} else {
$json = array('success' => true, $data);
}
echo json_encode($json);
Then in your JS code: 然后在您的JS代码中:
function(data) {
var serverdata = jQuery.parseJSON(data);
if (serverdata.success) {
... it worked
} else {
... something blew up, handle it
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.