'__pendingCallbacks[...].async' is null or not an object: callback async[i]...FIX :)

In my prior both articles about CALLBACK, which considered as Article of the Day @ www.asp.net recently might have problem:

Here i would like to talk about async indexer problem and of course solution as well :)

PROBLEM 1: '__pendingCallbacks[...].async' is null or not an object

EXPLANATION: if you debug then error message says, there is some problem with indexer [i] of async callback, hmmm you might not get that error message after using callback but developing other modules/part of the website you might get such error 1 day as i did :D, so if you are brainy enough, you must think something new i did which cause this ripple effect and go ahead to look for that what exactly i did and if you keep thinking with reading that error message carefully, you will get to know: somewhere you are using "i" variable and that variable is not being getting out of scope so mixing with "i" variable of callback async[i] and making problem.

Solutions:
1) solution is simple: follow standards and never make any variable name of single character rather use: anyhow either change your variable name from "i" to intCounter or anything u want

2) take care of your variable scope, so it wont mixup with variable "i"

3) use the following code/snippet: if you want to keep using your "i" variable in your code (may be you have used that at many places and don't wanna mess up with your existing code):

<script type="text/javascript">
function WebForm_CallbackComplete

_SyncFixed() {
  // SyncFix: the original version uses "i" as global thereby resulting in javascript errors when "i" is used elsewhere in consuming pages
  for (var i = 0; i < __pendingCallbacks.length; i++) {
   callbackObject = __pendingCallbacks[ i ];
  if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest .readyState == 4)) {
   // the callback should be executed after releasing all resources
   // associated with this request.
   // Originally if the callback gets executed here and the callback
   // routine makes another ASP.NET ajax request then the pending slots and
   // pending callbacks array gets messed up since the slot is not released
   // before the next ASP.NET request comes.
   // FIX: This statement has been moved 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);
   }

   // SyncFix: the following statement has been moved down from above;
   WebForm_ExecuteCallback (callbackObject);
  }
 }
}
window.onload = function Onloaad(){
if (typeof (WebForm_CallbackComplete) == "function") {
  // set the original version with fixed version
  WebForm_CallbackComplete = WebForm_CallbackComplete _SyncFixed;
}
}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值