我有一个简单的代码:
ajax.html
<html>
<head>
<title>AJAX</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
$(document).on("click", "#ajax-button", function() {
$.ajax({type: 'POST', url: 'ajax.php', data: ({ ajax: $('input[name="ajax"]').val() }),
success:function(data){
$('#result-ajax').html(data);
}
});
});
});
</script>
<input type="text" name="ajax" /> <button id="ajax-button">OK</button>
<div id="result-ajax"></div>
</body>
</html>
ajax.php
<?php
$ajax = intval($_POST['ajax']);
for ($i=0; $i < $ajax; $i++) {
echo $i;
sleep(3);
}
?>
我想实时变量,但现在我在循环后得到变量,我如何实时更新我的变量?我尝试设置async: false
,但它只是冻结窗口浏览器。