問題描述
我知道這個問題在這里發布了很多次,但我嘗試了所有我能找到的關于堆棧溢出的解決方案,但都沒有奏效.我只是試圖做一個簡單的ajax 查詢來加載一個div 內的頁面.就這么簡單:
I know this question was posted so many times in here, but I tried all the solutions I could find on stack overflow and none of them worked. I'm just trying to make a simple ajax query to load a page inside a div. Just as simple as:
function loadHome(){
$('#container').html('<div class="loader"></div>');
$.ajax({
type: "GET",
url: "home.php",
success: function(msg){
$("#container").html(msg);
}
});
}
在控制臺日志上我得到了
And on the console log I get
主線程上的同步 XMLHttpRequest 已被棄用,因為它會對最終用戶的體驗產生不利影響.如需更多幫助,請查看 http://xhr.spec.whatwg.org/
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/
除非我重新加載頁面,否則我在主頁上的一些 javascript 將無法工作.默認情況下,該頁面已在 div 中加載 home.php
,但我希望它加載其他頁面,然后當我單擊主頁"時它應該正常加載,并且由于該錯誤而沒有發生.我已經嘗試使用async:true",但沒有用.我不知道該怎么辦.
And some of my javascript on the home page will not work unless I reload the page. That page is by default loading home.php
inside the div already, but I want it to load other pages and then when I click "home" it should load normally, and that's not happening because of that error. I already tried to use "async: true", didn't work. I don't know what to do.
推薦答案
你應該使用本地 jquery 然后從 cdn
以及
You should use local jquery then from cdn
and also
為避免此警告,請勿使用:
To avoid this warning, do not use:
async: false
在您的任何 $.ajax()
調用中.這是 XMLHttpRequest
唯一被棄用的功能.
in any of your $.ajax()
calls. This is the only feature of XMLHttpRequest
that's deprecated.
默認值為 async: true
,因此如果您根本不使用此選項,那么如果該功能被真正刪除,您的代碼應該是安全的(它可能不會——它可能被從標準中刪除,但我敢打賭瀏覽器會繼續支持它很多年).
The default is async: true
, so if you never use this option at all, your code should be safe if the feature is ever really removed (it probably won't be -- it may be removed from the standards, but I'll bet browsers will continue to support it for many years).
參考
這篇關于主線程上的同步 XMLHttpRequest 已被棄用...嘗試了許多不同的解決方案的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!