我试图在我的load()
请求完成时开始动作,但alert
从不出现。请求load()
,因为我可以在.haha
div中看到mypage.html
的内容。这是非常简单的代码:完成.load()完成后的jQuery动作
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
Hello
<div class="haha"></div>
<script type="text/javascript">
$(document).ready(function(){
$('.haha').load('mypage.html', function(xhr) {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
alert('TEST TEST');
}
alert('TEST TEST');
});
});
</script>
没有警报出现。
编辑: 在我的控制台我有这样的:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
FAToolbar.js:1 Uncaught TypeError: $.cookie is not a function
你为什么要检查xhr状态? – Vixed
那么,在XHR状态下,它应该告诉我什么时候我的请求已完成并准备就绪。但尽管如此,使用或不使用它,它不工作 – Couteau
你不需要检查它。添加功能在最后它会起作用。删除if和函数变量。 **('。haha')。load('mypage.html',function(){alert('TEST TEST')}); ** – Vixed