Is there any dif开发者_如何学Goference between setting:
$.ajax({
type: "POST",
traditional: true,
url: '/adminTask/doAction',
async: false, <<<<<<<<<<<<<< HERE
data: parms,
dataType: "json",
success: function (data) {
$("#rdy_msg").text("Completed: " + id);
},
error: function () {
var cdefg = data;
}
});
and:
$.ajaxSetup({
async: false
});
The reason I ask is that I recently posted a question and one person mentioned for me to use ajaxSetup and set async: false. However I thought it was already set in the code at the top.
The difference is that using ajaxSetup
will affect all AJAX calls, unless you override it in the specific settings for that call.
As you set the async
property in the specific settings for that call, it won't be affected by the ajaxSetup
setting.
Yeah, you're right. Only use ajaxSetup
if you want all future ajax calls to default to it.
ajaxSetup
makes the settings the default for all futher calls to ajax
. You won't have to repeat that setting every time you do an AJAX call.
This is documented in $.ajaxSetup
:
All subsequent Ajax calls using any function will use the new settings
The difference is that using $.ajaxSetup effects all future ajax calls where as the first example you posted only defines the settings for that one request.
http://api.jquery.com/jQuery.ajaxSetup/
The first is for that request only, while ajaxSetup affects the defaults of all Ajax calls.
http://api.jquery.com/jQuery.ajaxSetup/
精彩评论