gpt4 book ai didi

jQuery ajax 事件调用顺序

转载 作者:行者123 更新时间:2023-12-01 02:48:45 25 4
gpt4 key购买 nike

假设我有一个像这样的简单函数。

$('body').ajaxSuccess(
function(){alert('global');}
);

$.post('http://www.google.com',
{ name: "John", time: "2pm" } ,
function(data,s,xhr) {
alert('local');
}
);

http://jsfiddle.net/AT5vt/

是否可以在本地成功回调之前调用全局 ajaxSuccess() 函数?因为我想在本地函数进一步处理之前对结果进行全局检查。

最佳答案

这是ajax事件调用顺序

if ( fireGlobals ){
jQuery.event.trigger("ajaxStart");
}
//Before send event
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
// Abort if not done already and return
return jqXHR.abort();
}
if ( isSuccess ) {
// Success Event
deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
} else {
// Error Event
deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
}

if ( fireGlobals ) {
globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
[ jqXHR, s, isSuccess ? success : error ] );
}
//Complete event
completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );

if ( fireGlobals ) {
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
jQuery.event.trigger("ajaxStop");
}
}

关于jQuery ajax 事件调用顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5481389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com