在 firefox 中正常工作,但在 IE 和 chrome 完成脚本后更新

In firefox works normally but in IE and chrome update after finished script

我想用 async=false ajax 制作脚本来制作一些控件并保存。 我想向用户展示这方面的进展。但是在 IE 和 chrome 中,在完成整个脚本后更新 Label1。火狐工作正常。有人知道我做错了什么吗??

感谢您的帮助。

mydata.php

if ($_POST['oper']=='wait')
 {
  sleep(2);
 }   

代码

function myFunc()
 {
  $.ajax({ type: 'POST',cache: false, url: 'mydata.php', data: {oper: 'wait'}, dataType: 'json', async: false});
  $('#Label1').html('1');
  $.ajax({ type: 'POST',cache: false, url: 'mydata.php', data: {oper: 'wait'}, dataType: 'json', async: false});
  $('#Label1').html('2');
  $.ajax({ type: 'POST',cache: false, url: 'mydata.php', data: {oper: 'wait'}, dataType: 'json', async: false});
  $('#Label1').html('3');
  }




 <span name='Label1' id='Label1'>XXX</span><button onclick='myFunc()'>Save</button>

试试这个:

function myFunc()
{
  $.ajax({ type: 'POST',cache: false, url: 'mydata.php', data: {oper: 'wait'}, dataType: 'json', async: false});
  $('#Label1').delay('1000').html('1');
  $.ajax({ type: 'POST',cache: false, url: 'mydata.php', data: {oper: 'wait'}, dataType: 'json', async: false});
  $('#Label1').delay('1000').html('2');
  $.ajax({ type: 'POST',cache: false, url: 'mydata.php', data: {oper: 'wait'}, dataType: 'json', async: false});
  $('#Label1').delay('1000').html('3');
  }

但我建议您使用 Ajax Success/Complete 函数,而不是等待 ajax 完全完成。

像这样:

$.ajax({ type: 'POST', cache: false, url: 'mydata.php', data: {oper: 'wait'}, dataType: 'json', async: false, success: function() { /* Do whatever you want here when your ajax has been successful. */}, error: function() { /* Here you can handle the errors thrown by ajax */ alert(e);}, complete: function() { /* Put the code here what you want to run irrespective of success or error. */ }})

对不起 post,你好吧。 async=false 已弃用,我必须找到另一种方式。感谢您的帮助。