2016-11-18 95 views
0

我有(2)jquery自動完成控件背靠背。當我在第一個框中輸入並選擇一個值,然後在第二個框中輸入並選擇一個值時,一切進展順利。如果我然後回到第一個文本框並輸入一個值,我將從第二個自動完成控件中收到錯誤消息。jquery結果不一致

任何想法? 這是第一個文本框

 $("#txtCIPCriteria").autocomplete({ 
     source: function (request, response) { 
      $.ajax({ 
       async: false, 
       delay: 250, 
       url: $('#hdfldPath').val(), 
       data: "{ 'Name': '" + request.term.replace(/'/g, "\&apos") + "'}", 
       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.split('|')[0], 
          val: item.split('|')[1] 
          //label: item.Text, 
          //value: item.Value 
         } // end of return 
        })) // end of response 
       } // end of success 
      });  // end of ajax 
     }, // end of source 
     select: function (e, i) { 
      $("#hdfldCIPCode").val(i.item.val); 
     }, 
     change: function (event, ui) { 
       if (!ui.item) { 
        $(event.target).val(''); 
       } 
      }, 
     minLength: 2 
    });  // end of $("#txtCIPCriteria").autocomplete 

這是第二控制

 $("#txtBuildingsCriteria").autocomplete({ 
     source: function (request, response) { 
      $.ajax({ 
       async: false, 
       delay: 250, 
       url: $('#hdfldPath').val(), 
       data: "{ 'Name': '" + request.term.replace(/'/g, "\&apos") + "'}", 
       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.split('|')[0], 
          val: item.split('|')[1] 
          //label: item.Text, 
          //value: item.Value 
         } // end of return 
        })) // end of response 
       } // end of success 
      });  // end of ajax 
     }, // end of source 
     select: function (e, i) { 
      $("#hdfldBuilding").val(i.item.val); 
      //    GetFiscalAgents1(i.item.val); 
      var CipCode = $('#hdfldCIPCode').val(); 
      var Bldg = $("#hdfldBuilding").val(); 
      var ProgType = $('#ddlProgramType').val(); 

      GetFiscalAgents1(i.item.val); 
      GetProspRegion(i.item.val); 

      //var Result = FindCIPCodeCount(CipCode, Bldg, ProgType) 
      //if (Result == 'Exists') { 
      // MsgBox('This is an active CIPCode, Building and ProgramType combination already. Please change your criteria.'); 
      //} 
      //else { 
      // $("#hdfldBuilding").val(i.item.val); 
      // GetFiscalAgents1(i.item.val); 
      // GetProspRegion(i.item.val); 
      //} 
     }, 
     change: function (event, ui) { 
        if (!ui.item) { 
         $(event.target).val(''); 
        } 
       }, 
     minLength: 3 
    });  // end of $("#txtBuildingsCriteria").autocomplete   
+0

我不知道它是否涉及到這個問題,但你不應該嘗試創建自己的JSON,請在對象上使用'JSON.stringify()'。 – Barmar

+0

你有什麼錯誤? – Barmar

+0

另外,在JSON中,字符串必須用雙引號包圍,而不是單個qoutes。所以'''{'Name':...}「'是錯的,因爲'Name'必須用雙引號。 – Barmar

回答

0

儘量把cache: false AJAX功能內