Php AJAX和blockUI
我想用插件显示“等待”消息。php文件是Php AJAX和blockUI,php,jquery,ajax,Php,Jquery,Ajax,我想用插件显示“等待”消息。php文件是 <?php sleep(2); $arr = array('m' => 'OK'); echo json_encode($arr); ?> 如何在使用ajax之前显示“loading…”消息以获得“OK”,并在使用ajax之后隐藏?现在它在使用后显示和隐藏。我还需要ajax json中的“async:false”。同时,该块显示两秒 谢谢在jQueryAjax中,他们的属性名为“beforeSend”,如下所示 $.ajax({
<?php
sleep(2);
$arr = array('m' => 'OK');
echo json_encode($arr);
?>
如何在使用ajax之前显示“loading…”消息以获得“OK”,并在使用ajax之后隐藏?现在它在使用后显示和隐藏。我还需要ajax json中的“async:false”。同时,该块显示两秒
谢谢在jQueryAjax中,他们的属性名为“beforeSend”,如下所示
$.ajax({
type: 'POST',
dataType: 'json',
url: 'ajax.php',
async: false,
data: {},
beforeSend: function(){
showLoadingScreen();
},
success: function(data) {
alert(data.m);
},
complete: function(data){
$.unblockUI();
}
});
function showLoadingScreen()
{
//include block.js for using this
$.blockUI({
message: 'Loading....',
css: {
border: 'none',
width: '300px',
height: '50px',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}
});
}
有一件事,json_encode返回json值,它不回显:回显json_encode($arr);Rest是正常的,应该可以工作,消息在呼叫之前显示,在收到响应时隐藏(可能太快了,看不见)。您应该向他显示
complete()
也一样,因为他想在呼叫完成时隐藏消息。这是因为您的ajax在本地计算机上运行得非常快,只需删除警报并检查或将代码部署到服务器上即可。我在我的project@Johan检查我的成功功能我正在调用$.unbui,因此不需要完成:)@Johan woops nicecatch+1:)没有来自complete()的帮助。我更新了这个。我想它显示了两秒钟的刷新和一个按钮点击。
$.ajax({
type: 'POST',
dataType: 'json',
url: 'ajax.php',
async: false,
data: {},
beforeSend: function(){
showLoadingScreen();
},
success: function(data) {
alert(data.m);
},
complete: function(data){
$.unblockUI();
}
});
function showLoadingScreen()
{
//include block.js for using this
$.blockUI({
message: 'Loading....',
css: {
border: 'none',
width: '300px',
height: '50px',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}
});
}