首页 > 解决方案 > jQuery hide() 函数不适用于警告框

问题描述

我在 ajax 调用期间遇到了 jQuery hide 方法的问题。
当 ajax 方法启动时,加载器 div 会正确显示,但在成功(或错误)方法中,加载器 div 仅在警报框关闭后才会隐藏。

$.ajax({
type: 'GET',
url: 'ajax/myfile.php',
dataType: 'json',
data: {'id':id, 'message':message},
beforeSend: function() {
  // Show image container
  $("#loader").show();
},  
success: function(result, textStatus, jqXHR) {
  $("#loader").hide();
  alert(result.message);
},  
error: function(jqXHR, textStatus, errorThrown) {
  $("#loader").hide();
  //Display the error.
  alert(textStatus+': '+errorThrown);
}

我该怎么做才能使加载程序 div 立即隐藏?

标签: jqueryajax

解决方案


推荐阅读