首页 > 解决方案 > 检查 Jquery Post 请求结果是否已满载

问题描述

我使用 $.post 并将结果放在 html div 中。有时 $.post 请求在结果内容完全加载之前停止。如何处理 $.post 请求,直到全部加载?

$(document).ready(function(){
    $("#content").html('<img height="150" width="150" src="spinner.gif" id="spinner"></div>');
    $.post("getdata.php", 
    { id:  "<?php echo $id ?>",
    language:  "<?php echo $language ?>"
    }, function(result){        
        $("#content").html(result);         
    });
});

标签: javascriptjqueryajax

解决方案


var jqxhr = $.post( "example.php", function() {
      alert( "success" );
    })
      .done(function() {
        alert( "second success" ); //You can append your html in this function
      })
      .fail(function() {
        alert( "error" );
      })
      .always(function() {
        alert( "finished" );
      }

);

以此作为参考


推荐阅读