2015-04-17 31 views
0

我有一個帶單選按鈕和自動完成輸入字段的web表單。根據所選的單選按鈕,需要調用不同的Web服務(url)以處理用戶在輸入字段中輸入的數據。 以下代碼運行良好,但我不知道如何讓它更靈活地接受不同的URL。有多個來源的jquery自動完成

 $("#txtCriteria").autocomplete({ 
    source: function (request, response) { 
     $.ajax({ 
      async: false, 
      delay: 500, 
      url: "../../CommonWebServices/wsEntity.asmx/ReportBuildings", 
      data: "{ 'Name': '" + request.term + "'}", 
      dataType: "json", 
      type: "POST", 
      contentType: "application/json; charset=utf-8", 
      dataFilter: function (data) { return data; }, 
      success: function (data) { 
       response($.map(data.d, function (item) { 
        return { 
         label: item.Text, 
         value: item.Value 
        } // end of return 
       })) // end of response 
      } // end of success 
     });  // end of ajax 
    }, // end of source 
    minLength: 1, 
}); 

這裏是單選按鈕。所以如果我選擇Region,那麼Web服務的URL就不一樣了。

     <input id="Radio1" type="radio" value="S" name="rblRptChoice" class="label" checked="checked" />State Wide<br /> 
       <input id="Radio2" type="radio" value="P" name="rblRptChoice" class="label" />Prosperity Region<br /> 
       <input id="Radio3" type="radio" value="R" name="rblRptChoice" class="label" />Region<br /> 
       <input id="Radio4" type="radio" value="T" name="rblRptChoice" class="label" />Cluster<br /> 
       <input id="Radio5" type="radio" value="C" name="rblRptChoice" class="label" />CEPD<br /> 
       <input id="Radio6" type="radio" value="F" name="rblRptChoice" class="label" />Fiscal Agency<br /> 
       <input id="Radio7" type="radio" value="B" name="rblRptChoice" class="label" />Building<br /> 
       <input id="Radio8" type="radio" value="P" name="rblRptChoice" class="label" />CIP Code<br /> 
       <input id="Radio9" type="radio" value="Y" name="rblRptChoice" class="label" />Year<br /><br /> 
       <asp:Label ID="lblDetails" runat="server" Text="Enter Details"></asp:Label><br /> 
       <input id="txtCriteria" type="text" placeholder="Enter Criteria" style="width:250px" /> 

任何幫助表示讚賞。

+0

每次自動完成搜索新術語時,都會調用「源」函數。沒有什麼能夠阻止你在ajax調用中創建'url:'值,這取決於當前選擇的任何無線電輸入 – blgt

回答

0

當選擇單選按鈕時,將路徑值放入變量中,然後將url設置爲變量。