嘿,我在做什么错在这里?非常新阿贾克斯。
Hey What am I doing wrong here? Extremely new to 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("http://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。我该如何解决这个问题?
It logs in just fine and gives the success message just fine just no luck on the window.location.replace. How can I fix this?
推荐答案
看起来 data.error
是真实的,即使你在成功分支。尝试把警报,以澄清你的程序流程。
It looks like data.error
is true, even though you ended up in the success
branch. Try putting alerts to clarify your program flow.
成功:功能(数据){
警报('成功分行');
$('#等待)隐瞒(500)。
$('#空)显示(500);
。$('#信息)removeClass移除()addClass((data.error ===真)错误:成功)
的.text(data.msg).show(500)
如果(data.error ===假)
警报(无数据错误);
window.location.replace(http://blahblah.com/usercp.php);
如果(data.error ===真)
警报(数据错误);
$('#寄存器)显示(500);
$('#空)。隐藏()
}
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("http://blahblah.com/usercp.php");
if (data.error === true)
alert('data error');
$('#reg').show(500);
$('#empty').hide()
},
相关推荐
最新文章