[转载]__pendingCallbacks[...].async' 为空或不是对象

本文介绍了一个关于ASP.NET AJAX同步回调中出现的问题及其解决方案。具体表现为__pendingCallbacks[i].async为空或不是对象的情况,文章提供了修改后的JavaScript代码来解决这一问题,并确保回调能够正确执行。

__pendingCallbacks[...].async' 为空或不是对象

<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(){
if (typeof (WebForm_CallbackComplete) == "function") {
  // set the original version with fixed version
  WebForm_CallbackComplete = WebForm_CallbackComplete_SyncFixed;
}
}
</script>

转载于:https://www.cnblogs.com/olartan/archive/2009/05/19/1460000.html

/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.media; import java.util.Arrays; import java.util.List; import android.content.Intent; import android.content.IntentFilter; import android.content.Context; import android.content.BroadcastReceiver; import android.util.Log; import android.app.ActivityThread; /** * @hide * * damon.zhang Block app too frequent getStreamVolume */ public class NtAudioManager { private static final String TAG = "NtAudioManager"; private long preGetVolumeTime = 0; private String preGetVolumePkg = ""; private int mLastIndex = 0; private static NtAudioManager mNtAudioManager; private static String mPkg; private static final BroadcastReceiver mNtAmReceiver; public NtAudioManager(String pkg) { mPkg = pkg; } public static NtAudioManager getNtAudioManager(Context contex, String pkg) { //if (!mGetStreamVolumeBlackList.contains(pkg)) { // return null; //} Context context = ActivityThread.currentApplication(); if (mNtAudioManager == null && context != null && mNtAmReceiver == null) { mNtAudioManager = new NtAudioManager(pkg); initReceiver(contex); } return mNtAudioManager; } private static final List<String> mGetStreamVolumeBlackList = Arrays.asList(new String[] { "com.tencent.mobileqq", "com.tencent.mtt", "com.tencent.mm", "com.tencent.KiHn", "com.google.android.youtube", "com.google.android.apps.youtube.music", "com.google.android.googlequicksearchbox", "com.facebook.katana", "com.instagram.android", "com.truecaller", "com.miHoYo.hkrpg", "com.spotify.music", "ahaflix.tv", "com.vkontakte.android", "com.vk.equals", "com.microsoft.appmanager", "com.jio.media.ondemand", "com.kiloo.subwaysurf", "com.hongsong.live.lite", "com.nothing.smartcenter" }); public static int[] LAST_STREAM_VOLUME = new int[] { -1, // STREAM_VOICE_CALL -1, // STREAM_SYSTEM -1, // STREAM_RING -1, // STREAM_MUSIC -1, // STREAM_ALARM -1, // STREAM_NOTIFICATION -1, // STREAM_BLUETOOTH_SCO -1, // STREAM_SYSTEM_ENFORCED -1, // STREAM_DTMF -1, // STREAM_TTS -1, // STREAM_ACCESSIBILITY -1, // STREAM_ASSISTANT }; public int getVolume(int streamType) { return LAST_STREAM_VOLUME[streamType]; } public void setVolume(int index, int streamType){ LAST_STREAM_VOLUME[streamType] = index; } public boolean isInitVolume(String pkgName, int streamType) { ensureValidStreamType(streamType); //if (!mGetStreamVolumeBlackList.contains(pkgName)) { // return false; //} if (LAST_STREAM_VOLUME[streamType] == -1) { return false; } return true; } private void ensureValidStreamType(int streamType) { if (streamType < 0 || streamType >= LAST_STREAM_VOLUME.length) { throw new IllegalArgumentException("Bad stream type " + streamType); } } private void initReceiver(Context con) { mNtAmReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) { int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); int currentVolume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1); int lastVolume = intent.getIntExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, -1); int streamTypeAltas = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE_ALIAS, -1); Log.i(TAG, "mNtAudioManager: "+ mNtAudioManager + " mPkg: " + mPkg + " streamType : " + streamType + " streamTypeAltas: " + streamTypeAltas + " currentVolume: " + currentVolume + " lastVolume: " + lastVolume); LAST_STREAM_VOLUME[streamType] = currentVolume; } } }; IntentFilter intentFilter = new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION); con.registerReceiver(mNtAmReceiver, intentFilter, null, null); } }
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值