2011-09-26 85 views
0

我被ajaxStart/ajaxSend及其最終方法卡住了一點。我有2個不同的AJAX調用使用jQuery.post在2個文本輸入上運行。第一個是從我的數據庫中獲取特定名稱列表,並且我使用ajaxStart/ajaxStop來顯示和隱藏微調器。這工作正常。下一個AJAX調用,用於檢查電子郵件狀態,再次在我的數據庫中。我再次使用ajaxStart/ajaxStop以顯示一個包含進程正在進行的消息的div,然後在該進程完成之後。 現在,我的問題是,當我輸入第一個文本輸入時,第二個輸入的ajaxStart被調用,並且我可以看到div!我嘗試使用ajaxSend和ajaxComplete,但沒有運氣!在2個不同的文本輸入上使用ajaxStart&ajaxStop時發生衝突

代碼:

//First request 
jQuery('.company-name input').keyup(function(event){ 
    //get the alphabets and post them using jQuery.post. 
}); 

jQuery('.company-name input').ajaxStart(function(){ 
    //Show the spinner 
}); 
jQuery('.company-name input').ajaxStop(function(){ 
    //hide the spinner 
}); 

//Second Request 
jQuery('.reviewer-email input').blur(function(){ 
    //check the email rights using jquery.post 
}); 

jQuery('.reviewer-email input').ajaxStart(function(){ 
    //Show the warning 
}); 
jQuery('.reviewer-email input').ajaxStop(function(){ 
    //hide the warning 
}); 

當第一個關鍵事件發生時,「顯示警告」部分運行!我也嘗試了ajaxSend和ajaxComplete,但沒有奏效!

任何想法如何我可以在我的輸入框分別打電話給他們?

由於

+0

你可以發佈您的代碼? – Jags

回答

0

.ajaxStart() documentation描述的,當被觸發ajaxStart事件已註冊與.ajaxStart()方法所有處理程序被執行。

你的情況的一種可能的解決辦法是剛剛離開了ajaxStart/ajaxStop方法:

//First request 
jQuery('.company-name input').keyup(function(event){ 
    //Show the spinner 

    //get the alphabets and post them using jQuery.post. 
    //in jQuery.post success handler hide the spinner 
}); 

//Second Request 
jQuery('.reviewer-email input').blur(function(){ 
    //Show the warning 

    //check the email rights using jquery.post 
    //in jQuery.post success handler hide the warning 
}); 
+0

感謝您的回覆! 我正在使用jQuery.post調用來處理大量dom元素的成功處理程序。我只想在請求/響應循環進行時才顯示微調/警告。沒有ajaxStart/ajaxStop方法可能嗎?我能否爲2種不同的文本輸入附加2種不同的方法? 我會嘗試成功回調方法,看看它是如何發展的。 –

+0

您好卡雷爾,您的解決方案工作!再次感謝! –

相關問題