我試圖在我的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