我只是觉得我很聪明。事实证明我错了。
我的ajax登录工作正常。我用它来将用户名附加到链接中,效果也非常好。
在页面的子集中,我希望它刷新页面。这也非常有效。
但是,刷新会停止附加 href。我检查了一下,可以看到用户名?=“此处的用户名”正在运行,并且立即更改为用户名?=
我认为只有当 if 语句为 true 时才会发生重新加载。?
if(data.success == true){
var thisPage = window.location.pathname;
var refreshArray = new Array("training_chap01.php","training_chap02.php")
if(jQuery.inArray(thisPage,refreshArray)){
location.reload();
}
$('#loggedIn').show();
$('a[href="userProfile.php?username="]').each(function(){
this.href += username;
});
$('#loginContent').slideToggle();
$('#loggedOut').hide();
感谢您的帮助。
最佳答案
inArray
返回一个索引,而不是 bool 值,试试这个:
if(jQuery.inArray(thisPage,refreshArray) > -1)
关于javascript - 如果 inArray 中断了 href 附加,则 Ajax 成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17884732/