2010-08-03 59 views
2

我正在調用圖像滑塊的鼠標懸停的頁面方法來顯示數據庫中的圖像。問題是我得到多個回調。有誰知道如何解決這個問題?我使用的頁方法,頁面方法多個回調

代碼:

var contextArray = "img"; 
pageMethodConcept = { 
    callServerSideMethod: function (id) { 
     PageMethods.GetItemLargeImage(id, pageMethodConcept.callback, pageMethodConcept.Failcallback, contextArray); 

    }, callback: function (result, userContext, imagePreview) { 
     //alert(result); 
     if (userContext = "img") { 
      //replace img source with result 
      document.getElementById("displayPreviewImage").src = result; 

      return false; 
     } 
    }, Failcallback: function (result, userContext) { 
     alert("failed"); 
    } 
} 

代碼設置定時器:僅在一定的時間量傳遞

var alertTimer = 0; 

if (alertTimer == 100) { 
    alert("time 100"); 
    alertTimer = setTimeout(pageMethodConcept.callServerSideMethod(this.id), 0); 

} 
else { 
    alertTimer = setTimeout(pageMethodConcept.callServerSideMethod(this.id), 100); 
    alert("time "); 
} 

回答

1

您認爲計時器代碼正在做什麼?

if (alertTimer == 100) {...

100?什麼是100?

setTimeout and clearTimeout

你應該做這樣的事情:

if (alertTimer != 0) { 
    /* timeout pending */ 
    clearTimeout(alertTimer); 
    alertTimer = ... 
} else { 
    /* set timeout */ 
    alertTimer = ... 
} 
0

添加一個計時器,併發送回調從最後一次回調。你可以用櫃檯來做。

+0

嘿感謝sugesstion我有東西給u是什麼您通過設置定時器的意思只是檢查,看看,因爲它不與工作方法,但多次調用的問題已解決。 我在編輯我的問題 – mehul9595 2010-08-03 10:51:26