[英]Add div while ajax loading
I put this code: 我把这段代码:
<script type='text/javascript' src='http://code.jquery.com/jquery-2.1.0.min.js'></script>
<script type="text/javascript">
$(document).ajaxStart(function() {
$("#loading-image").show();
});
$(document).ajaxStop(function() {
$("#loading-image").hide();
});
on the top of the page... 在页面顶部...
and I have HTML: 而且我有HTML:
<body style="">
<div id="loading-image" style="width:100%; height:100%; background:#ccc; display:none;"></div>
But I dont see ID loading image on ajax... What can be a problem here? 但是我没有看到ID在ajax上加载图像...这里可能有什么问题?
From the limited amount that you posted, it doesn't look like you're actually making an AJAX request. 从您发布的有限数量来看,您似乎并没有真正提出AJAX请求。 http://jsfiddle.net/volte/A66C8/
http://jsfiddle.net/volte/A66C8/
Try then making an ajax call when the page loads: 尝试在页面加载时进行ajax调用:
$.ajax({
url: "test.html",
context: document.body
});
Disclaimer: I have not tested this. 免责声明:我尚未对此进行测试。 Pulled from http://api.jquery.com/jQuery.ajax/
从http://api.jquery.com/jQuery.ajax/中拉出
In addition, make sure you wrap those methods in an onload. 另外,请确保将这些方法包装在onload中。 Most people do:
大多数人这样做:
(function() {
//... your code here ...
//... will be run on load...
});
The code doesn't seems to have anything wrong, make sure that those methods are in fact beeing called whenever you use ajax, put a breakpoint in the element inspector. 该代码似乎没有任何问题,请确保每当您使用ajax时,实际上都会调用那些方法,并在元素检查器中放置一个断点。 Also check if when you manually remove display:none from the "loading-image" div you can see it on the screen, just to be sure.
另外,请检查是否在手动删除display:none时从屏幕上看到它,只是为了确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.