gpt4 book ai didi

javascript - Django - ajax 调用加载页面不起作用

转载 作者:行者123 更新时间:2023-11-28 04:54:23 25 4
gpt4 key购买 nike

我真的需要帮助..

我对前端不太擅长,对Ajax很迷茫。

当我点击表格的按钮时,我尝试执行 Ajax 调用,因此当我点击该按钮时,我的 ajax 应该显示我的动画 .gif,以便用户应该知道页面正在加载。

我的模板:

<style>
.ajaxProgress{
display:none;
text-align: center;

}
</style>
<div id="output">
<div class="ajaxProgress">
<h3>Please wait..</h3>
<img src="{% static 'img/ajax.gif' %}" alt="loading"/>
</div>
</div>
{% for item in qs %}
<tr>
<tbody>
<td
a id="mqtt" class="btn btn-xs btn-info" title="mqtt" href="javascript: startAjax(){% url 'start_mqtt' item.id %}"><span class="fa fa-signal"></span> </a> </td>
</tbody>
</tr>
{% endfor %}
</table>


<script>

function startAjax() {
$('.ajaxProgress').show();
$.ajax({
type: "GET",
dataType:"json",
async: true,
data: { csrfmiddlewaretoken: '{{ csrf_token }}' },
success: function(json){
$('#output').html(json.message);
$('.ajaxProgress').hide();
GetRating(json.message);
}
})

}
</script>

基本上我需要的是当我点击按钮时应该启动我的 .gif 但什么也没有发生......

最佳答案

var $loading = $('.ajaxProgress').hide();
$(document)
.ajaxStart(function () {
$loading.show();
})
.ajaxStop(function () {
$loading.hide();
});

我喜欢用这种方式

关于javascript - Django - ajax 调用加载页面不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42662910/

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