在结果出现之前显示加载 GIF
我有一个很长的查询,需要几秒钟才能显示结果。它是对外部脚本的 ajax 调用。如何在 div 内部显示加载消息,但在显示结果后加载消息消失?
这是函数: >
function findstore(){
var txt = 'Please enter the zip code to find the closest store <input type="text" name="zipcode" id="zipcode">';
$.prompt(txt,{
buttons:{Confirm:true, Cancel:false},
submit: function(v,m,f){
var flag = true;
if (v) { }
return flag;
},
callback: function(v,m,f){
if(v){
var zipcode = f.zipcode;
$.post('findstore.php',{zip:zipcode},
function(data){
$("div#demo").html(data);
}
);
}
}
});
}
>
I have a query that is quite long and takes a few seconds to display the results. It is an ajax call to an external script. How can I display a loading message inside of the div, but have the loading message disappear once the results are displayed?
Here is the function:
>
function findstore(){
var txt = 'Please enter the zip code to find the closest store <input type="text" name="zipcode" id="zipcode">';
$.prompt(txt,{
buttons:{Confirm:true, Cancel:false},
submit: function(v,m,f){
var flag = true;
if (v) { }
return flag;
},
callback: function(v,m,f){
if(v){
var zipcode = f.zipcode;
$.post('findstore.php',{zip:zipcode},
function(data){
$("div#demo").html(data);
}
);
}
}
});
}
>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的逻辑中,您可以在调用回调方法之前加载动画 gif。您可以将按钮点击与将 gif 加载到 div 所需的代码相关联。
然后,一旦您返回数据(在
function(data){}
内),您就可以通过用返回的数据替换 的内容来删除 gif。In your logic you can load the animated gif inside the just before calling your callback method. You can associate the button cick with the code needed to load the gif into the div.
Then as soon as you get data back (inside
function(data){}
) you can remove the gif by replacing the content of the with the returned data.