javascript - 检查 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);
});
});
解决方案
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" );
}
);
以此作为参考。
推荐阅读
- excel - 如何将分号分隔的文件转换为csv
- python - 在 Python 中使用二次规划/最小化来最小化受线性约束的范数
- javascript - 如何在vuejs中的回调函数中将值存储在变量中
- angular - Angular rxjs EffectsModule 导入
- javascript - 为什么 Google Chrome 控制台中的常量称为“常量变量”?
- java - 将数字值附加到java中的数组
- webpack-dev-server - 当我尝试运行我的 webpack-dev-server 时,它给了我以下错误,找不到该模块
- css - 在网格行之间单击时插入组件
- list - 在序言中删除列表项的问题
- purescript - 有没有更好的方法从 sum 类型中解开记录?