'__pendingCallbacks[...].async' 错误

 
问题描述:在调用AJAX javascript 时出现
Microsoft JScript runtime error: '__pendingCallbacks[...].async' is null or not an object”;
的错误。
这种错误大多数发生在:
第一种情况:AJAX 调用里面包含有AJAX—callback的函数;
第二种情况:如果在处理回调的函数中用了一个变量名为“i”,听起来这个问题很奇怪,但确时是这样的。
CASE 1:
是因为 AJAX中调用中含有回调事件,
下面这个例子是说明这个问题的:函数 doSomeAjaxCall中调用服务器方法,前处理返回值,
在下一次调用时,在任何一个回调函数中就会出现这种错误。也许我说的不是很
清楚,其实我是第一次翻译这种文档的。
// Used by AjaxValidator to initialte the callback to server.
        function doSomeAjaxCall(validatorInstance)
        {        
 
            WebForm_DoCallback('__Page', “someParam1”,                                                        OnValidationSuccess, “someParam2”, null, true)    
        }
 
        function OnValidationSuccess(newValue, imageInstance)
        {   
            // do something...
           
            //This causes the error
             WebForm_DoCallback('__Page', "", OnSecondCallSuccedded,
            "Update", null, true)  ;  
        }
 
        function OnSecondCallSuccedded (newValue, imageInstance)
        {
            // do something...
        }
解决1
解决这个问题,其实AJAX框架在客户端的WebForm_CallbackComplete()中存在一个错误,
在每一次执行回调是都要调用它的,它的说明在一个动态生成的AXD-file中。在AJAX中的每一个调用函数显示为“被调用”,在这个清单中调用这个清单中被标识的,但这种调用
线路不是安全的。
想象一个:在第一次执行回调时,会执行到WebForm_CallbackComplete()。此时回调标记次数是1,当第二次调用时,调用(WebForm_DoCallback),并返回信息,此时回调标记次数是 2
   因为变量i,在WebForm_CallbackComplete中不是从1开始,而是从2开始了。
// Used by AjaxValidator to initialte the callback to server.
        function doSomeAjaxCall(validatorInstance)
        {        
 
            WebForm_DoCallback('__Page', “someParam1”,                                                        OnValidationSuccess, “someParam2”, OnValidationError, true)    
        }
 
        function OnValidationSuccess(newValue, imageInstance)
        {   
            setTimeout(“renderSuccess(‘” + newValue + “’)”, 1);
        }
 
        function OnValidationError(newValue, imageInstance)
        {
           
        }
 
function renderSuccess(newValue)
{
           
            // Do something
           
            //This does not cause the error
             WebForm_DoCallback('__Page', "", OnUpdateSuccedded,
            "Update", OnUpdateError, true)  ;  
}
CASE 2
由于变量i的原因,你在使用回的函数中使用了变量i;
设想你在使用回调的函数之后,它是从AJAX framework框架中处理回调,
function OnValidationSuccess(newValue, imageInstance)
        {   
            for(i = 0; i < 4; i++ )       
            {
                //Do anything
            }
        }
执行时会产生 “Microsoft JScript runtime error: '__pendingCallbacks[...].async' is null or not an object” 的错误。
解决这个问题非常简单,仅只需将使用的变量I换一个就可以了,
如: function OnValidationSuccess(newValue, imageInstance)
        {   
            for(n = 0; n < 4; n++ )       
            {
                //Do anything
            }
        }
  这个问题在于WebForm_CallbackComplete这个函数中使用了全局变量i
这样如果你在你的程序中使用了I,那么就冲充了。
Reamrks
动态生成的AXD—CODE为
function WebForm_PostBackOptions(eventTarget, eventArgument, validation, validationGroup, actionUrl, trackFocus, clientSubmit) {
    this.eventTarget = eventTarget;
    this.eventArgument = eventArgument;
    this.validation = validation;
    this.validationGroup = validationGroup;
    this.actionUrl = actionUrl;
    this.trackFocus = trackFocus;
    this.clientSubmit = clientSubmit;
}
function WebForm_DoPostBackWithOptions(options) {
    var validationResult = true;
    if (options.validation) {
        if (typeof(Page_ClientValidate) == 'function') {
            validationResult = Page_ClientValidate(options.validationGroup);
        }
    }
    if (validationResult) {
        if ((typeof(options.actionUrl) != "undefined") && (options.actionUrl != null) && (options.actionUrl.length > 0)) {
            theForm.action = options.actionUrl;
        }
        if (options.trackFocus) {
            var lastFocus = theForm.elements["__LASTFOCUS"];
            if ((typeof(lastFocus) != "undefined") && (lastFocus != null)) {
                if (typeof(document.activeElement) == "undefined") {
. . .
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值