Alert on jquery ajax requst when new response
Posted: 03 Jun 2017, 06:44
I have a jquery ajax function that is called every second, with setTimeout().
I want an alert to pop up whenever a new message is received.
Here's the ajax code to receive the message from server.
Where should i put alert('New message received'); so that it only pops up only when a new message is received?
If i put alert in success function it is popping up every second.
I want an alert to pop up whenever a new message is received.
Here's the ajax code to receive the message from server.
Code: Select all
$(document).ready(function ajax(){
$.ajax({
type: 'GET',
url: 'recieve.php',
dataType: 'html',
success: function(response){
$("#message").html(response);
},
complete: function(){
setTimeout(ajax,1000);
}
});
});
If i put alert in success function it is popping up every second.