检查Jquery Post请求结果是否已满载

时间:2018-12-27 10:15:44

标签: javascript jquery ajax

我使用$ .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);         
    });
});

1 个答案:

答案 0 :(得分:-1)

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" );
      }

);

遵循this作为参考。

相关问题