[英]Why ajax call give error of Synchronous XMLHttpRequest on the main thread is deprecated?
我正在ASP.net MVC5中進行分配。 當我執行ajax調用時,成功轉到動作方法(已調試)。 但是之后,當我對其進行標記並附加到主體時,它會在jquery min.js中給出錯誤,並且控制台上的錯誤是:不贊成在主線程上使用同步XMLHttpRequest,因為它對最終用戶的體驗有不利影響。 jquery-1.11.0.min.js:4未捕獲的ReferenceError:未定義$ document
我的代碼如下:
$.ajax({
url: url,
type: "GET",
contentType: "application/json; charset=utf-8",
cache: false,
async: false,
success: function (data, status) {
if (status && data) {
var Markup = data;
var Title = Id && Id != null ? "edit" : "New";
$AddEdit = BootstrapModal.createAndShow("modal", Title, Markup); // this is another method in JS
}
},
error: function () {
alert("not workig");
}
});
Bootstrap方法是:
var createAndShow = function (ElementId, Title, Markup) {
debugger;
//Here some markup is creating and append to body
$("body").append(Markup); //Here error come
您面臨的錯誤:“不贊成在主線程上使用同步XMLHttpRequest,因為它會對最終用戶的體驗產生不利影響。有關更多幫助,請訪問http://xhr.spec.whatwg.org/ ”
全部說明。 通過在以下行中對其進行顯式設置,您正在使用同步Ajax調用:
async: false,
不推薦使用。 如果適用,請將其更改為true。 但是,在極少數情況下,同步ajax調用可能有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.