国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Bootstrap進度條與AJAX后端數(shù)據(jù)傳遞結(jié)合使用實例詳解

2024-05-06 15:18:11
字體:
供稿:網(wǎng)友

很多時候,我們執(zhí)行頁面上某個URL請求的時候,需要有等待的時間。如果是直接的頁面跳轉(zhuǎn),瀏覽器會有緩沖進度展示,但是如果是AJAX,我覺得應該自己加上進度條,等待數(shù)據(jù)全部接收到之后,進度條消失,展示頁面。

在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');//服務器停止了5秒,sleep(5),假設是查詢數(shù)據(jù)用了5秒  //setTimeout("$('#searchModal').modal('hide')",2000); //設置2000毫秒之后模態(tài)框消失     $('#searchModal').on('hidden.bs.modal', function () { //    // 執(zhí)行一些動作...   $("#homeworkContent").html(mydata); //顯示后端傳遞的結(jié)果   }); },  error : function() {   alert("calc failed");  } }); </script>

以上所述是小編給大家介紹的Bootstrap進度條與AJAX后端數(shù)據(jù)傳遞結(jié)合使用,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網(wǎng)站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 岐山县| 呼图壁县| 安顺市| 田东县| 新泰市| 石城县| 丰镇市| 溆浦县| 肇庆市| 双牌县| 鲜城| 临夏县| 桦川县| 老河口市| 宜丰县| 措勤县| 灵寿县| 平昌县| 陆良县| 九龙城区| 阳泉市| 荃湾区| 吴江市| 西充县| 乳源| 尉犁县| 介休市| 社旗县| 德江县| 东平县| 内江市| 两当县| 天等县| 囊谦县| 自贡市| 桂阳县| 汽车| 百色市| 乐业县| 淳安县| 二连浩特市|