2012-02-13 23 views
1

如果自動完成適用於錯誤/失敗情況,您可以幫我解決如何刪除微調器/加載圖像嗎?刪除微調器/加載圖像中的自動完成錯誤

如果我得到錯誤「由於意外的錯誤,我們無法加載數據」我看到加載的圖像,我想刪除該圖像。

下面是摘錄

$("Autotxt").autocomplete({ 
    source: function (request, response) { 
     $.ajax({ 
      type: "POST", 
      contentType: "application/json; charset=utf-8", 
      url: "Webservice.asmx/GetNames", 
      data: "{'prefixText':'" + request.term + "'}", 
      dataType: "json", 
      success: function (data) { 
       response($.map(data.d, function (item) { 

        return { 
         label: item.split('|')[0], 
         val: item.split('|')[1] 
        } 
       })) 
      }, 

      error: function (result) { 

       alert("Due to unexpected errors we were unable to load data"); 
       ServiceFailed(result); 
      }, 
      failure: function (response) { 
       alert("Due to unexpected errors we were unable to load data"); 

      } 
     }); 
    }, 
    select: function (event, ui) { 
     txtSoID(ui.item.val); 
    }, 
    minLength: 4 
}); 


function txtID(val) 
{ 
alert(val) 
} 
+0

你是什麼形象的HTML? – 2012-02-13 13:56:37

回答

2

我沒有看到你的代碼中的任何加載屏幕。但是你可以簡單地添加功能

var removeSpinner = function() { 
    $("yourloader").hide(); 
} 

,並調用它在你的失敗或錯誤回調像

error: function (result) { 
     removeSpinner(); 
     alert("Due to unexpected errors we were unable to load data"); 
     ServiceFailed(result); 
    } 
3

如果你指的是可通過用戶界面加載類,你應該能夠做到以下內容:

​​

我發現了jqueryUI development site類的信息在這裏只講CSS和主題頁面的底部。

0

在這些圖像上執行一個檢查元素,檢查它們的類(例如,'loader'),然後將其放入錯誤和失敗回調中$(".loader").hide()

+0

這會刪除dom節點並阻止它再次被調用。 – danwit 2012-02-13 14:24:27

+0

編輯代碼以隱藏這些元素,而不是刪除。 – 2012-02-13 15:26:52

0

從我的答案在這裏改編,添加以下代碼搜索後執行完成(甚至0結果):

var __response = $.ui.autocomplete.prototype._response; 
$.ui.autocomplete.prototype._response = function(content) { 
    __response.apply(this, [content]); 
    this.element.trigger("autocompletesearchcomplete", [content]); 
}; 

該代碼會觸發一個事件(autocompletesearchcomplete),然後可以綁定到:

$("#q").bind("autocompletesearchcomplete", function(event, contents) { 
    /* Remove spinner here */ 
}); 

希望這有助於...