Ajax/jQuery的新手。我迄今試過的所有東西都失敗了。我有一個動態的標題,用於顯示鏈接,如果登錄,如果沒有登錄。爲什麼我的div在Ajax調用後不會顯示自己?
使用簡單的PHP如果其他顯示鏈接。
登錄下拉,在提交jQuery/Ajax函數時調用。一旦成功,我希望LoggedOut隱藏它的功能。但是LoggedIn拒絕顯示自己。
我不能在css中使用display:none,因爲這個頭文件和鏈接應該總是存在。
請幫助我,讓我可以停止皺眉和抓頭:)非常感謝。
success: function(data) {
$("#statusLogin").hide();
if(data.success == true){
$('#loggedIn').show(); //GAAAAAAAAAAAH!!!!!
$('#loginContent').slideToggle();
$('#loggedOut').hide();
}else{
// alert("data.message... " + data.message);//undefined
$("#error").show().html(data.message);
}
},
編輯:HTML
<?php if($general->loggedIn()){ ?>
<nav class = "memberHeaderArea" id="loggedIn">
<ul>
<li>
<a href="userProfile.php?username=<?php echo $user['username'];?>">Profile<span class="user icon"></span></a>
</li>
<li>
<a href="userLogout.php">Log out<span class="lock icon"> </span></a>
</li>
</ul>
</nav>
<?php
//toplinks for when not logged in
}else{ ?>
<nav class = "memberHeaderArea" id ="loggedOut">
<ul>
<li id="login">
<a id="loginTrigger" href="#">Login<span class="unlock icon"></span></a>
<div id="loginContent">
<form method="post" action="" id="ourLoginFormID_JS">
<div id="error"></div>
<div class="ourContactFormElement2">
<label for="username">Username:</label>
<input type="text" id="username" name="username" autocomplete="off" class="required" value="<?php if(isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
</div>
<div class="ourContactFormElement2">
<label for="password">Password:</label>
<input type="password" id="password" name="password" autocomplete="off" class="required"/>
</div>
<div class="ourContactFormElement2">
<label> </label>
<input type="submit" name="loginButton" id="loginButton" value="Login!" onclick="validLogin(); return false;"/>
</div>
<div id="statusLogin"></div>
</form>
</div>
</li>
<li>
<a href="userRegister.php">Register<span class="adduser icon"></span></a>
</li>
</ul>
</nav>
<?php
}
?>
是否有任何在JavaScript控制檯中的錯誤?檢查拼寫錯誤,並記住它是區分大小寫的。 – Barmar
服務器的迴應是什麼? –
@Barmar,沒有我能看到的錯誤。沒有錯別字。我已經檢查,然後再次檢查 – null