2014-09-25 58 views
0

我已經與jquery.getScriptjQuery的getScript加入無視我的路

一個問題,我加載我的代碼以

$.getScript("assets/global/plugins/datatables/media/js/jquery.dataTables.min.js?" + Math.random()) 

,但在瀏覽器的控制檯,我有這個錯誤

http://localhost:53968/UI/WebPages/jquery.dataTables.min.js.map 404 (Not Found) 

這是頁面和腳本的結構

/UI/WebPages/calling_pages.aspx 個/UI/WebPages/assets/global/plugins/datatables/media/js/jquery.dataTables.min.js

所以,如果我把一個直接

<script type='text/javascript' src='assets/global/plugins/datatables/media/js/jquery.dataTables.min.js'></script> 

一切工作,但我需要測試如果JS被加載,以防止多個負載

+0

刪除您的js文件上的//#sourceMappingURL? – Malk 2014-09-25 22:35:08

+0

謝謝你這是工作。現在我想我使用這種方式,但我必須在我的代碼中解決這個問題,因爲插件不是我的,也許我將來可能會遇到這個問題。謝謝 – 2014-09-26 19:52:15

回答

0

docs

$.getScript("ajax/test.js") 
.done(function(script, textStatus) { 
    console.log(textStatus); 
}) 
.fail(function(jqxhr, settings, exception) { 
    $("div.log").text("Triggered ajaxError handler."); 
}); 

我的查詢參數從

改變
"...jquery.dataTables.min.js?" + Math.random() 

"...jquery.dataTables.min.js?ver=1.10.2" 

,因爲你沒有改變文件或者有自帶的更新,是不是。我認爲這是更新瀏覽器緩存的最佳價值。但要小心,在文檔中提供了啓用緩存的提示:

// By default, $.getScript() sets the cache setting to false. 
// This appends a timestamped query parameter to the request URL 
// to ensure that the browser downloads the script each time it 
// is requested. You can override this feature by setting the cache 
// property globally using $.ajaxSetup(): 

$.ajaxSetup({ 
    cache: true 
});