I am using the following ajax get function to check the status of a user. Is it possible to set async: false
with this shorthand method? If not how can this be changed so that I can add async false?
我使用以下ajax get函数来检查用户的状态。是否可以使用此简写方法设置async:false?如果不是如何更改,以便我可以添加async false?
$.get("/submit/checkuser/", function (userStatus) {
if (userStatus == 'Disabled') { // check if user if disabled
} else if (userStatus == 'Deleted') { // check if user if deleted
} else {
};
}).fail(function () {
connectionError();
});
5 个解决方案
#1
4
This might work for you
这可能对你有用
$.ajax({
url : "/submit/checkuser/",
type : "get",
async: false,
success : function(userStatus) {
if (userStatus == 'Disabled') { // check if user if disabled
} else if (userStatus == 'Deleted') { // check if user if deleted
} else {
};
},
error: function() {
connectionError();
}
});
#2
18
The only way to make a synchronous $.get
call is to set ajaxSetup to synchronous:
进行同步$ .get调用的唯一方法是将ajaxSetup设置为synchronous:
jQuery.ajaxSetup({async:false});
This is considered bad form though, since it affects every ajax call made by JQuery on the page. I would suggest just biting the bullet and using the more elaborate jQuery.ajax
syntax.
这被认为是不好的形式,因为它会影响JQuery在页面上发出的每个ajax调用。我建议只是咬紧牙关并使用更精细的jQuery.ajax语法。
See How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request? for a fuller discussion.
请参阅如何让jQuery执行同步而非异步的Ajax请求?进行更全面的讨论。
#3
3
From above though, I use it like this
从上面来看,我这样使用它
jQuery.ajaxSetup({async:false});
// my code
jQuery.ajaxSetup({async:true});
#4
1
Try this.
$.get('/your/url/dot/com', { async: false }, function(data){
globalBaseURL = data;
});
#5
0
Use jQuery.ajaxSetup({async:false});
because $.get()
is Jquery shorthand method with syntax jQuery.get( url [, data ] [, success ] [, dataType ] )
and to make changes to setting there is jQuery.get( [settings ] )
使用jQuery.ajaxSetup({async:false});因为$ .get()是Jquery的简写方法,语法为jQuery.get(url [,data] [,success] [,dataType])并且对设置进行更改时有jQuery.get([settings])
#1
4
This might work for you
这可能对你有用
$.ajax({
url : "/submit/checkuser/",
type : "get",
async: false,
success : function(userStatus) {
if (userStatus == 'Disabled') { // check if user if disabled
} else if (userStatus == 'Deleted') { // check if user if deleted
} else {
};
},
error: function() {
connectionError();
}
});
#2
18
The only way to make a synchronous $.get
call is to set ajaxSetup to synchronous:
进行同步$ .get调用的唯一方法是将ajaxSetup设置为synchronous:
jQuery.ajaxSetup({async:false});
This is considered bad form though, since it affects every ajax call made by JQuery on the page. I would suggest just biting the bullet and using the more elaborate jQuery.ajax
syntax.
这被认为是不好的形式,因为它会影响JQuery在页面上发出的每个ajax调用。我建议只是咬紧牙关并使用更精细的jQuery.ajax语法。
See How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request? for a fuller discussion.
请参阅如何让jQuery执行同步而非异步的Ajax请求?进行更全面的讨论。
#3
3
From above though, I use it like this
从上面来看,我这样使用它
jQuery.ajaxSetup({async:false});
// my code
jQuery.ajaxSetup({async:true});
#4
1
Try this.
$.get('/your/url/dot/com', { async: false }, function(data){
globalBaseURL = data;
});
#5
0
Use jQuery.ajaxSetup({async:false});
because $.get()
is Jquery shorthand method with syntax jQuery.get( url [, data ] [, success ] [, dataType ] )
and to make changes to setting there is jQuery.get( [settings ] )
使用jQuery.ajaxSetup({async:false});因为$ .get()是Jquery的简写方法,语法为jQuery.get(url [,data] [,success] [,dataType])并且对设置进行更改时有jQuery.get([settings])