2015-12-11 35 views
0

我jQuery中有這個功能,它使用.load打開一個彈出的div在頁面上同步的XMLHttpRequest:JQuery的錯誤 - 主線程

function LoadModal(page, title) { 
    title = title || ''; 

    $("#modal_page").fadeIn("slow"); 
    $("#modal_title").html(title); 

    $("#modal_page_body").html('<h2 align="center">Loading...</h3><p align="center"><i class="fa fa-refresh fa-spin fa-5x"></i></p>'); //$('#LoadingDiv').show(); 
    $("#modal_page_body").load(page, function(){ 

    }); 
    $("html, body").animate({ scrollTop: 0 }, "slow"); 
} 

當我調用這個函數,我的控制檯顯示此錯誤:

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/. 

回答

2

UPDATE

嘗試使用$.ajax()並添加ajaxPrefilter()

$.ajaxPrefilter(function(options, originalOptions, jqXHR) { 
    options.async = true; 
}); 

$.ajax({ 
    url: page, 
    success:function(data) { 
     // make an action after call is finished 
     $("#modal_page_body").html(data); 
     } 
}) 
+0

不,還是一樣的警告信息 – charlie

+0

什麼是頁面url? json或其他? –

+0

好的,請嘗試我的更新 –