gpt4 book ai didi

jquery - 使用ajax发布时显示加载图像

转载 作者:行者123 更新时间:2023-12-03 21:32:10 25 4
gpt4 key购买 nike

我知道互联网上有数千个示例,但我希望脚本在检索数据时必须显示加载的 gif 图像。我的java知识很差,因此我问如何更改以下内容:

<script type="text/javascript"> 
$(document).ready(function(){
function getData(p){
var page=p;
$.ajax({
url: "loadData.php?id=<? echo $id; ?>",
type: "POST",
cache: false,
data: "&page="+ page,
success : function(html){
$(".content").html(html);
}
});
}
getData(1);

$(".page").live("click", function(){
var id = $(this).attr("class");
getData(id.substr(8));
});
});
</script>

我的 div 在这里:

    <div class="content" id="data"></div>

谢谢。约翰

最佳答案

假设您在页面上的某个位置有一个标签,其中包含您的加载消息:

<div id='loadingmessage' style='display:none'>
<img src='loadinggraphic.gif'/>
</div>

您可以在 ajax 调用中添加两行:

function getData(p){
var page=p;
$('#loadingmessage').show(); // show the loading message.
$.ajax({
url: "loadData.php?id=<? echo $id; ?>",
type: "POST",
cache: false,
data: "&page="+ page,
success : function(html){
$(".content").html(html);
$('#loadingmessage').hide(); // hide the loading message
}
});

关于jquery - 使用ajax发布时显示加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2509711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com