jQuery技术:JQuery登录重定向。 包含的代码

嘿我在这里做错了什么? 非常新的ajax。

$(document).ready(function(){ $('#submit').click(function() { $('#waiting').show(500); $('#empty').show(500); $('#reg').hide(0); $('#message').hide(0); $.ajax({ type : 'POST', url : 'logina.php', dataType : 'json', data: { type : $('#typeof').val(), login : $('#login').val(), pass : $('#pass').val(), }, success : function(data){ $('#waiting').hide(500); $('#empty').show(500); $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success') .text(data.msg).show(500) if(data.error === false) window.location.replace("https://blahblah.com/usercp.php"); if (data.error === true) $('#reg').show(500); $('#empty').hide() }, error : function(XMLHttpRequest, textStatus, errorThrown) { $('#waiting').hide(500); $('#message').removeClass().addClass('error') .text("There was an Error. Please try again.").show(500); $('#reg').show(500); $('#empty').hide(); Recaptcha.reload(); } }); return false; }); 

});

它只是很好地登录并在window.location.replace上提供成功消息就好了。 我怎样才能解决这个问题?

    看起来data.error是真的,即使你最终进入了success分支。 尝试发出警报以澄清您的程序流程。

    success : function(data){ alert('success branch'); $('#waiting').hide(500); $('#empty').show(500); $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success') .text(data.msg).show(500) if(data.error === false) alert('no data error'); window.location.replace("https://blahblah.com/usercp.php");
    if (data.error === true) alert('data error'); $('#reg').show(500); $('#empty').hide() },

    试试这个:

     ... if(data.error === 'false') window.location.replace("https://stackoverflow.com"); ... 

    要么

     ... if(data.error == 'false') window.location.replace("https://stackoverflow.com"); ... 

    你错过了一些分号(将在IE中破解):

     $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success') .text(data.msg).show(500); //<- HERE (...) $('#empty').hide(); // <- HERE 

    编辑:现在你使用了很多显示/隐藏事件,你想显示一条消息,然后进行重定向。 您应该在show事件结束时链接重定向(因此show动画会等到结束之前执行重定向:

     $('#message').removeClass() .addClass((data.error === true) ? 'error' : 'success') .text(data.msg).show(500, function(){ if(data.error === false) window.location.replace("https://blahblah.com/usercp.php"); (...) }); 

    但无论如何,其他答案肯定包含了你的bug的主要原因。 即调试data.error中的内容,它可能不是假的。

    需要了解更多jQuery教程分享JQuery登录重定向。 包含的代码,都可以关注jQuery技术分享栏目---计算机技术网(www.ctvol.com)!

      以上就是jQuery教程分享JQuery登录重定向。 包含的代码相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/982505.html

      (0)
      上一篇 2021年12月13日
      下一篇 2021年12月13日

      精彩推荐