Skip to content

Instantly share code, notes, and snippets.

@martin0258
Created November 30, 2012 10:33
Show Gist options
  • Save martin0258/4175037 to your computer and use it in GitHub Desktop.
Save martin0258/4175037 to your computer and use it in GitHub Desktop.
Simple asynchronous processing with jquery ajax
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Ajaxtest</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// Test whether ajax call works or not
$(document).ready(function(){
$('#button').click(function(){
// user clicks "Run"
$('#status').text('Running');
// call preRun to get ID
// simulation of polling for status update.
var timer = setInterval("progress()", 100);
// simulation of starting to run a long service. callback when it finishes
$.get('longservice.php', function(data){
$('#status').text(data);
clearInterval(timer);
});
});
});
function progress()
{
$('#status').append('.');
}
</script>
</head>
<body>
<input type="button" name="Run" id="button" value="Run" style="width:300; height:300; font-size:50px">
<div id="status"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment