標籤:cat table XML google ajax載入 ted als check sys
問題: 當項目啟動登入後,google瀏覽器(F12)或fireFox等瀏覽器會出現如下警告:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user‘s experience. jquery-1.8.0.min.js:2 For more help, check https://xhr.spec.whatwg.org/.
| send |
@ |
jquery-1.8.0.min.js:2 |
| |
ajax |
@ |
jquery-1.8.0.min.js:2 |
| |
(anonymous) |
@ |
notice.js?v=201502100941:26 |
| |
k |
@ |
jquery-1.8.0.min.js:2 |
| |
fireWith |
@ |
jquery-1.8.0.min.js:2 |
| |
ready |
@ |
jquery-1.8.0.min.js:2 |
| |
D |
@ |
jquery-1.8.0.min.js:2
|
經檢查發現,在對應的*.js中,在進行ajax操作時,async設定有問題,如下:
原因:附加元件目對應的*.js時,若主*.js中ajax使用async: false,而後面的*.js中使用async: true,就會造成ajax載入不同步,從而出現上面警告。
async: true,(預設是true),ajax請求是非同步;
async: false,
ajax請求是同步的;此時ajax請求將整個瀏覽器鎖死,只有*.js對應的*.jsp頁面執行結束後,才可以執行其它操作。
例如:notice.js$(function() { $.ajax({ type: "POST", url: "querySysNoteByParam.do?rows=5", dataType: "json",
async: false, success: function(data) { var list = $("#list-tpl").html(), item = $("#item").html(); var row = ""; var $tab = $(".note-list"); $.
each(buildData(data), function(i, n) { var temp = ""; $.each(n.data, function(a, b) { temp += item.replace(/\$itemTitle/g, StringUtils._encodeHTML((StringUtils.getStrLength(b.noteTitle) > 16 ? (b.noteTitle.substring(0, 16) + "...") : b.noteTitle))).replace(/\$Titlelong/g, StringUtils._encodeHTML(b.noteTitle)).replace(/\$id/g, b.id).replace(/\$dateTime/, b.publishDate.substring(0, 10)); }); row += list.replace(/\$title/g, n.title).replace(/\$list/, temp).replace(/\$noteType/g, n.noteType); }) $tab.html(row); } });}); 修改成:
async: true, 這樣就不會出現那個警告了。
ajax中的async設定問題