Bootstrap進(jìn)度條與AJAX后端數(shù)據(jù)傳遞結(jié)合使用實(shí)例詳解
很多時候,我們執(zhí)行頁面上某個URL請求的時候,需要有等待的時間。如果是直接的頁面跳轉(zhuǎn),瀏覽器會有緩沖進(jìn)度展示,但是如果是AJAX,我覺得應(yīng)該自己加上進(jìn)度條,等待數(shù)據(jù)全部接收到之后,進(jìn)度條消失,展示頁面。
在Yii框架里面使用了AJAX后,覺得前后端的數(shù)據(jù)交互變得方便多了。
下面直接貼代碼啦
控制器Controller
public function actionTest(){ if(isset($_POST["number"])){ $html = “success”; }else{ $html ="something wrong"; } sleep(5); echo $html; Yii::app()->end(); }
View視圖
<!-- 模態(tài)框(Modal) --> <div class="modal fade" id="searchModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-body"> <div id='modal_message' style="text-align: center"><h2>正在查詢中.....</h2></div> <div class="progress progress-striped active"> <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 100%;"> <span class="sr-only">100% 完成</span> </div> </div> </div> </div><!-- /.modal-content --> </div><!-- /.modal --> </div> <script type="text/javascript"> $("#searchModal").modal("show");//顯示“正在查詢”字樣的模態(tài)框 htmlobj = $.ajax({ url:"/Controller/test", type : 'POST', data : { "number" : "123", }, dataType : "text", //contentType : 'application/x-www-form-urlencoded', async : true, success : function(mydata) { $('#searchModal').modal('hide');//服務(wù)器停止了5秒,sleep(5),假設(shè)是查詢數(shù)據(jù)用了5秒 //setTimeout("$('#searchModal').modal('hide')",2000); //設(shè)置2000毫秒之后模態(tài)框消失 $('#searchModal').on('hidden.bs.modal', function () { // // 執(zhí)行一些動作... $("#homeworkContent").html(mydata); //顯示后端傳遞的結(jié)果 }); }, error : function() { alert("calc failed"); } }); </script>
以上所述是小編給大家介紹的Bootstrap進(jìn)度條與AJAX后端數(shù)據(jù)傳遞結(jié)合使用,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- BootstrapTable refresh 方法使用實(shí)例簡單介紹
- Bootstrap table中toolbar新增條件查詢及refresh參數(shù)使用方法
- BootStrap Table后臺分頁時前臺刪除最后一頁所有數(shù)據(jù)refresh刷新后無數(shù)據(jù)問題
- Bootstrap的Refresh Icon也spin起來
- bootstrap select2插件用ajax來獲取和顯示數(shù)據(jù)的實(shí)例
- 使用vue框架 Ajax獲取數(shù)據(jù)列表并用BootStrap顯示出來
- bootstrap jquery dataTable 異步ajax刷新表格數(shù)據(jù)的實(shí)現(xiàn)方法
- 使用Bootstrap Tabs選項卡Ajax加載數(shù)據(jù)實(shí)現(xiàn)
- DataTables+BootStrap組合使用Ajax來獲取數(shù)據(jù)并且動態(tài)加載dom的方法(排序,過濾,分頁等)
- bootstrapTable+ajax加載數(shù)據(jù) refresh更新數(shù)據(jù)
相關(guān)文章
被jQuery折騰得半死,揭秘為何jQuery為何在IE/Firefox下均無法使用
某學(xué)員前日實(shí)施一個Web項目實(shí)施發(fā)生了悲劇,找到我求解決,把我也折騰個半死。2010-01-01JS實(shí)現(xiàn)去除數(shù)組中重復(fù)json的方法示例
這篇文章主要介紹了JS實(shí)現(xiàn)去除數(shù)組中重復(fù)json的方法,涉及javascript針對json數(shù)組數(shù)據(jù)的遍歷、判斷、存取等相關(guān)操作技巧,需要的朋友可以參考下2017-12-12詳解JavaScript數(shù)組和字符串中去除重復(fù)值的方法
這篇文章主要介紹了詳解JavaScript數(shù)組和字符串中去除重復(fù)值的方法,及利用各種限制條件對數(shù)組和字符串進(jìn)行過濾,需要的朋友可以參考下2016-03-03p5.js實(shí)現(xiàn)聲音控制警察抓小偷游戲示例解析
這篇文章主要為大家介紹了p5.js實(shí)現(xiàn)聲音控制警察抓小偷游戲示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04如何使用工具規(guī)范前端項目的commits與changelog技巧
這篇文章主要為大家介紹了如何使用工具規(guī)范前端項目的commits與changelog技巧詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02