I am reading about Ajax Events from the jQuery docs.
My jQuery code with some HTML:
<p style="display:none">Loading...</p>
<div></div>
$(document).ready(function() {
$("p")
.ajaxStart(function(){
$(this).show();
})
.ajaxStop(function(){
$(this).hide();
});
$.ajax({
url : 'http://localhost/xampp/web_development/new_study_2014/my_files/test.php',
data : {id : 123},
type : "GET",
dataType : "html",
success: function(response) {
$("div").hide().html(response).fadeIn(1500);
},
error: function(xhr, status, errorThrown) {
console.log( xhr + status + errorThrown );
},
complete: function() {
console.log( );
}
});
});
The PHP:
<?php
sleep(1);
echo "<p> his name is jack</p>";
?>
I wanted the paragraph that says Loading... to display when the ajax request starts and hides when it is finished. As described in the jQuery docs. Yet it does none of the two and displays "his name is jack" from the php page. What am I doing wrong?