Although it's not necessary to use AJAX for this, you can use something like below.
Considering you have an element that has a username and password like below:
<div id="login">
<label for="txtUsername">Username:</label>
<input type="text" id="txtUsername" />
<label for="txtPassword">Password:</label>
<input type="password" id="txtPassword" />
<button id="btnLogin">Log In</buton>
</div>
<div id="logout" style="display: none;">
<a href="logout.php">Log Out</a>
</div>
Then, having jQuery already referenced call your PHP page ("login.php" in the example):
<script type="text/javascript">
$(function() {
$("#btnLogin").click(function() {
$.ajax({
url: "login.php",
data: {username: $("#txtUsername").val(), password: $("#txtPassword").val()},
success: function(data){
$("#login").toggle();
$("#logout").toggle();
}
});
});
});
</script>