Fixing "Microsoft JScript runtime error: '__pendingCallbacks[...].async' is null or not an object"

  • 1967
  • 0

Fixing "Microsoft JScript runtime error: '__pendingCallbacks[...].async' is null or not an object"

今天遇到了一個奇怪的問題

在頁面上使用

ICallbackEventHandler做ajax Callback時會發生這個錯誤
在網路上找了一下,應該是一個BUG,在這裡修改為jquery

                    function WebForm_CallbackComplete_SyncFixed() {
                        // the var statement ensure the variable is not global
                        for (var i = 0; i < __pendingCallbacks.length; i++) {
                            callbackObject = __pendingCallbacks[i];
                            if (callbackObject && callbackObject.xmlRequest &&
			            (callbackObject.xmlRequest.readyState == 4)) {
                                // SyncFixed: line move below // WebForm_ExecuteCallback(callbackObject);
                                if (!__pendingCallbacks[i].async) {
                                    __synchronousCallBackIndex = -1;
                                }
                                __pendingCallbacks[i] = null;
                                var callbackFrameID = "__CALLBACKFRAME" + i;
                                var xmlRequestFrame = document.getElementById(callbackFrameID);
                                if (xmlRequestFrame) {
                                    xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);
                                }
                                // SyncFixed: the following statement has been moved down from above;
                                WebForm_ExecuteCallback(callbackObject);
                            }
                        }
                    }
                    
                    $().ready(function () {
                        //Fix Bug
                        if (typeof (WebForm_CallbackComplete) == "function") {
                        // Set the fixed version
                        WebForm_CallbackComplete = WebForm_CallbackComplete_SyncFixed;                       
                    }
});

原出處:http://www.codeproject.com/KB/aspnet/pendingcallbacks.aspx