我的页面上有很多 mysql 查询。在完成之前,我想在我的页面上显示()一个模式。模态已准备就绪。
我的算法:
page.onload -> show loading modal
/*wait until all the queries end*/
hide loading modal.
我如何处理等待直到所有查询结束部分?
提前致谢。
---编辑---
我正在使用 laravel 调试栏。调试栏显示如下:
- -更新 -
Javascript 文件:
$(document).ready(function(){
$('#myTab a').on('load', function (e) {
e.preventDefault();
$(this).tab('show');
},onLoadMyTab());
}
function onLoadMyTab(){
//postRoute is on my routes.php and data is including the values
$.post("postRoute", function(data)){
//some javascript code, just for UI
}
}
路由.php
Route::post('postRoute', array(
'uses' => 'myController@myPostFunction'
'as' => 'postRoute'
));
myController.php
public function myPostFunction(){
//some database queries here, returning JSON to my onLoadMyTab js function
//which returns as data to onLoadMyTab js function.
}
希望我能说得通。
最佳答案
这里有几个问题:
- 您的 DOM 就绪处理程序中存在错误。在
$(...).on()
中,第三个参数是每当事件发出时调用的回调。 http://api.jquery.com/on/
您实际上将 undefined
传递到回调中,因为您调用了 onLoadMyTab
,它隐式返回 undefined。
您可能只想在 DOM 准备就绪时立即调用 onLoadMyTab
。
$(document).ready(onLoadMyTab);
$.post 将发出 ajax 请求并在请求完成时调用第二个参数。
function onLoadMyTab() { $.post("postRoute", function(data)){ // show modal with data here }); }
关于Javascript (jQuery) 加载模式直到数据库查询在 php 页面上结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30716511/