返回列表 發帖

XMLHttpRequest 不可在主線程會影響用戶體驗?

本帖最後由 lolmuta 於 2015-11-22 01:06 編輯

遇到錯誤訊息…
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience


下面程式碼,是將script 注入到"Javascript 討論"中
會在每個主題的旁邊顯示一個按鈕,當使用者按下按鈕後,會將網頁先以alert 的方式顯示(只會顯示網頁原始碼的文字)
再以jquery-ui dialog 的方式顯示出來(會將網頁解讀)
有引用jquery-ui

當一開始按的按鈕是可成功運行的,但是就出現上面的錯誤訊息,之後按下的按鈕就沒有效了。

然後我覺得很怪…
為什麼都已經是非同步了的寫法了?請問那裡同步了?
難道同步的是Jquery?



補充
後來有測試,若僅顯示alert而不用jquery-ui顯示dialog的話,就不會出錯,
若以jquery-ui dialog來顯示,錯誤訊息都是在下載圖檔時出錯,
Failed to load resource: the server responded with a status of 404 (Not Found)
$(document).ready(function(){
        $('th[class="subject common"]').each(function(){
                var get_href=$(this).find('a').attr("href");
                new_ele = $("<button type='button'>test</button>");
                new_ele.click(function(){                        
                        $.get(get_href,function(data){
                                alert(data);                                
                                $("<div></div>").html(data).dialog(
                                        {modal: true,
                                         width:600,
                                         height:400
                                });
                        });                        
                });
                $(this).append(new_ele);        
        });        
});
Yi

返回列表 回復 發帖