2015-03-31 35 views
0

我需要在JQuery中創建多個搜索請求,從不同的表/頁搜索,我需要將所有的搜索結果結合到一個HTML表,並顯示在UI中的結果。在後臺獲取數據,而不會影響UI在.net + jquery

下面是我的做法..

jQuery的使用$阿賈克斯,我去到服務器(.NET代碼),獲取JSON數據,回來的JS文件並生成一個HTML表,並顯示結果(此結果將有複選框供用戶檢查/取消選中結果)。一旦我顯示結果,我再次使用$ .ajax,轉到服務器(.NET代碼)並獲取數據,並將結果附加到第一個HTML表。

我的要求是,這兩個請求之間,我需要

1)顯示正在加載圖像/文本。

2)用戶應該能夠訪問(滾動,檢查,取消選中)第一個JSON請求返回的HTML表結果。

我能夠完成1)也。我面臨的問題是關於2)。 一旦結果來自第一個請求,並且一旦我在div中顯示結果,我再次使用$ .ajax觸發第二個搜索請求。目前我無法訪問HTML表格。頁面凍結,直到第二個請求的結果到來,並將結果綁定到HTML表格。

我的代碼是這樣的。

function SearchDetails() { 
GetDetails("Test", 0); /*Trigger First Request*/ } 

function GetDetails(searchKeyword, iAppend) { 
$.ajax({ 
    type: "POST", 
    url: "FETCH_DETAILS.asmx/GetDetails", 
    data: "{'searchKeyword':'" + searchKeyword + "', 'Append':'" + iAppend + "'}", 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    async: false, 
    crossDomain: true, 
    jsonp: false, 
    success: function (response) { 
     if(iAppend == 0) //First Request 
     { 
      BindTable(response.d, iAppend); //Creates new HTML table and binds results 
      GetDetails("TestNew", 1);//Trigger Second Request 
     } 
     else if (iAppend == 1) { 
      BindTable(response.d, iAppend); 
     } 
    }, 
    failure: function (msg) { 
     alert(msg); 
    }, 

});} 

function BindTable(SearchResults, iAppend){ 
/*Creates HTML Table & binds to a div for First Request 
Creates HTML Table Rowss & appends to existing HTML table for Second Request*/ } 

請建議我我是否錯過什麼,還是有辦法從jQuery的到服務器(.NET代碼),而不影響(獲得凍結)顯示/ UI。

+0

** [此鏈接](https://github.com/vadimsva/waitMe)**可能會給你的想法.. – 2015-03-31 07:05:00

回答

0

也許設置:

async: false 

async: true 
相關問題