Javascript Ajax登录不返回结果
我已经在模式中创建了一个登录框,但由于某种原因,我无法返回结果。我对javascript非常陌生,所以我猜这是显而易见的Javascript Ajax登录不返回结果,javascript,jquery,ajax,login,Javascript,Jquery,Ajax,Login,我已经在模式中创建了一个登录框,但由于某种原因,我无法返回结果。我对javascript非常陌生,所以我猜这是显而易见的 $('#login').click(function() { $("#buttons").hide(); $("#progress").show(); var email=$("#email").val(); var password=$("#password").val();
$('#login').click(function()
{
$("#buttons").hide();
$("#progress").show();
var email=$("#email").val();
var password=$("#password").val();
var dataString = 'email='+email+'&UserPW='+password;
if($.trim(email).length>0 && $.trim(password).length>0)
{
$.ajax({
type: "POST",
url: "includes/php/ajaxLogin.php",
data: dataString,
cache: false,
beforeSend: function(){
$("#buttons").hide();
$("#progress").show();
;},
success: function(data){
if(data)
{
console.log(data);
if (data = "client/staff")
{
$("#clientStaffToggleButtons").show();
}
if (data = "staff")
{
$("body").load("staff/dashboard.php").hide().fadeIn(1500).delay(6000);
}
if (data = "client")
{
$("body").load("myevent/dashboard.php").hide().fadeIn(1500).delay(6000);
}
if (data = "noEmail")
{
$("#buttons").show();
$("#progress").hide();
//Shake animation effect.
$('#formLogin').shake();
$("#signInSubmit").val('Sign In')
$("#error").html("<span style='color:#cc0000'>Error:</span> Invalid username and password. ");
}
if (data == "noPW")
{
$("#buttons").show();
$("#progress").hide();
//Shake animation effect.
$('#formLogin').shake();
$("#signInSubmit").val('Sign In')
$("#error").html("<span style='color:#cc0000'>Error:</span> Invalid username and password. ");
}
}
}
});
}
return false;
$('#登录')。单击(函数()
{
$(“#按钮”).hide();
$(“#进度”).show();
var email=$(“#email”).val();
var password=$(“#password”).val();
var dataString='email='+email+'&UserPW='+password;
如果($.trim(电子邮件).length>0&&$.trim(密码).length>0)
{
$.ajax({
类型:“POST”,
url:“includes/php/ajaxLogin.php”,
数据:dataString,
cache:false,
beforeSend:function(){
$(“#按钮”).hide();
$(“#进度”).show();
;},
成功:功能(数据){
如果(数据)
{
控制台日志(数据);
如果(data=“客户/员工”)
{
$(“#clientStaffToggleButtons”).show();
}
if(data=“staff”)
{
$(“body”).load(“staff/dashboard.php”).hide().fadeIn(1500).delay(6000);
}
如果(数据=“客户”)
{
$(“body”).load(“myevent/dashboard.php”).hide().fadeIn(1500).delay(6000);
}
如果(data=“noEmail”)
{
$(“#按钮”).show();
$(“#进度”).hide();
//抖动动画效果。
$('#formLogin').shake();
$(“#登录提交”).val('登录')
$(“#error”).html(“错误:无效的用户名和密码。”);
}
如果(数据==“noPW”)
{
$(“#按钮”).show();
$(“#进度”).hide();
//抖动动画效果。
$('#formLogin').shake();
$(“#登录提交”).val('登录')
$(“#error”).html(“错误:无效的用户名和密码。”);
}
}
}
});
}
返回false;
有什么想法可能是错误的吗
非常感谢
编辑
我只是想澄清一下,我正在取回函数(通过控制台日志),但它们在if-then语句中似乎并没有实际执行任何操作,例如:
如果(data=“客户/员工”)
似乎什么都没做,即使返回的数据是“客户/员工”
要测试它,请访问fiestausa.com,点击右上角的login(登录)不正确使用比较:
$('#login').click(function(e)
{
e.preventDefault();
$("#buttons").hide();
$("#progress").show();
var email=$("#email").val();
var password=$("#password").val();
var dataString = 'email='+email+'&UserPW='+password;
if($.trim(email).length>0 && $.trim(password).length>0)
{
$.ajax({
type: "POST",
url: "includes/php/ajaxLogin.php",
data: dataString,
cache: false,
beforeSend: function(){
$("#buttons").hide();
$("#progress").show();
;},
success: function(data){
if(data.d)
{
console.log(data.d);
if (data.d == "client/staff")
{
$("#clientStaffToggleButtons").show();
}
if (data.d == "staff")
{
$("body").load("staff/dashboard.php").hide().fadeIn(1500).delay(6000);
}
if (data.d == "client")
{
$("body").load("myevent/dashboard.php").hide().fadeIn(1500).delay(6000);
}
if (data.d == "noEmail")
{
$("#buttons").show();
$("#progress").hide();
//Shake animation effect.
$('#formLogin').shake();
$("#signInSubmit").val('Sign In')
$("#error").html("<span style='color:#cc0000'>Error:</span> Invalid username and password. ");
}
if (data.d == "noPW")
{
$("#buttons").show();
$("#progress").hide();
//Shake animation effect.
$('#formLogin').shake();
$("#signInSubmit").val('Sign In')
$("#error").html("<span style='color:#cc0000'>Error:</span> Invalid username and password. ");
}
}
}
});
}
$(“#登录”)。单击(函数(e)
{
e、 预防默认值();
$(“#按钮”).hide();
$(“#进度”).show();
var email=$(“#email”).val();
var password=$(“#password”).val();
var dataString='email='+email+'&UserPW='+password;
如果($.trim(电子邮件).length>0&&$.trim(密码).length>0)
{
$.ajax({
类型:“POST”,
url:“includes/php/ajaxLogin.php”,
数据:dataString,
cache:false,
beforeSend:function(){
$(“#按钮”).hide();
$(“#进度”).show();
;},
成功:功能(数据){
如果(数据d)
{
console.log(data.d);
if(数据d==“客户/员工”)
{
$(“#clientStaffToggleButtons”).show();
}
如果(数据d==“员工”)
{
$(“body”).load(“staff/dashboard.php”).hide().fadeIn(1500).delay(6000);
}
if(data.d==“客户机”)
{
$(“body”).load(“myevent/dashboard.php”).hide().fadeIn(1500).delay(6000);
}
如果(data.d==“noEmail”)
{
$(“#按钮”).show();
$(“#进度”).hide();
//抖动动画效果。
$('#formLogin').shake();
$(“#登录提交”).val('登录')
$(“#error”).html(“错误:无效的用户名和密码。”);
}
如果(数据d==“noPW”)
{
$(“#按钮”).show();
$(“#进度”).hide();
//抖动动画效果。
$('#formLogin').shake();
$(“#登录提交”).val('登录')
$(“#error”).html(“错误:无效的用户名和密码。”);
}
}
}
});
}
“return false”现在已被弃用。不正确使用比较:
$('#login').click(function(e)
{
e.preventDefault();
$("#buttons").hide();
$("#progress").show();
var email=$("#email").val();
var password=$("#password").val();
var dataString = 'email='+email+'&UserPW='+password;
if($.trim(email).length>0 && $.trim(password).length>0)
{
$.ajax({
type: "POST",
url: "includes/php/ajaxLogin.php",
data: dataString,
cache: false,
beforeSend: function(){
$("#buttons").hide();
$("#progress").show();
;},
success: function(data){
if(data.d)
{
console.log(data.d);
if (data.d == "client/staff")
{
$("#clientStaffToggleButtons").show();
}
if (data.d == "staff")
{
$("body").load("staff/dashboard.php").hide().fadeIn(1500).delay(6000);
}
if (data.d == "client")
{
$("body").load("myevent/dashboard.php").hide().fadeIn(1500).delay(6000);
}
if (data.d == "noEmail")
{
$("#buttons").show();
$("#progress").hide();
//Shake animation effect.
$('#formLogin').shake();
$("#signInSubmit").val('Sign In')
$("#error").html("<span style='color:#cc0000'>Error:</span> Invalid username and password. ");
}
if (data.d == "noPW")
{
$("#buttons").show();
$("#progress").hide();
//Shake animation effect.
$('#formLogin').shake();
$("#signInSubmit").val('Sign In')
$("#error").html("<span style='color:#cc0000'>Error:</span> Invalid username and password. ");
}
}
}
});
}
$(“#登录”)。单击(函数(e)
{
e、 预防默认值();
$(“#按钮”).hide();
$(“#进度”).show();
var email=$(“#email”).val();
var password=$(“#password”).val();
var dataString='email='+email+'&UserPW='+password;
如果($.trim(电子邮件).length>0&&$.trim(密码).length>0)
{
$.ajax({
类型:“POST”,
url:“includes/php/ajaxLogin.php”,
数据:dataString,
cache:false,
beforeSend:function(){
$(“#按钮”).hide();
$(“#进度”).show();
;},
成功:功能(数据){
如果(数据d)
{
console.log(data.d);
if(数据d==“客户/员工”)
{
$(“#clientStaffToggleButtons”).show();
}
如果(数据d==“员工”)
{
$(“body”).load(“staff/dashboard.php”).hide().fadeIn(1500).delay(6000);
}
if(data.d==“客户机”)
{
$(“正文”).l
if (data === "client/staff")
data = "client/staff";
if ("client/staff")