maccaj51
asked on
Jquery ajax: start getting data on click
Hi Experts,
I have this basically code:
It works fine but only gets the data on success. My php is running a foreach function and echoing the count as it goes. I would like to show this in the #count span, not just on success.
Any ideas?
Many thanks in advance
I have this basically code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Data</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$( "#delete" ).click(function() {
$('#loader').fadeIn();
$.ajax({
url: 'delete.php',
success: function(data) {
$('.loader').fadeOut();
$('#count').html(data);
}
});
});
});
</script>
</head>
<body>
<button id="delete">Delete Posts</button><br />
<span id="loader" style="display:none;">LOADING</span><br />
<span id="count"></span> <span>Posts Deleted</span>
</body>
</html>
It works fine but only gets the data on success. My php is running a foreach function and echoing the count as it goes. I would like to show this in the #count span, not just on success.
Any ideas?
Many thanks in advance
I have not tried this, but thinking out loud, could you use some type of progress bar and have your php update the progress bar where reaching 100% triggers what would be your success function?
http://jqueryui.com/progressbar/
http://jqueryui.com/progressbar/
If seeing the count is more important than efficiency you could get rid of the foreach and move control to a client side loop that fires a separate AJAX request for each iteration. On the face of it that would be pretty stupid, unless you really want to display that count.
Cd&
Cd&
could you use some type of progress bar and have your php update the progress bar where reaching 100% triggers what would be your success function?
@padas - php code cannot interact with the client side browser code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all your help
The php script has to finish first.
The server side and client side are dissociated processes. The client side makes an AJAX call to the server - the server completes the request and sends back the results - the AJAX then takes over again.
If you want to do this you would need to look at something like Comet or Node.js