ajax中的async設定問題

來源:互聯網
上載者:User

標籤: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設定問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.