亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Jquery 正在發送多個請求

Jquery 正在發送多個請求

九州編程 2021-11-04 15:58:58
我正在嘗試制作一個搜索欄,從輸入的信件中發送提案請求。jQuery 發送的請求數與輸入的字母數相同。如果我寫“sa”,jQuery 將發送 2 個請求。如果我寫“Sa”,jQuery 將發送 3 個請求(因為我按下了 shift,所以大字母被算作 2 個字母)。代碼應該像以下說明一樣工作: 用戶寫下他想要查找的名稱和數據庫中的代碼搜索,并顯示所有可能的搜索詞。 編輯: 腳本應發送 2 個請求:第一個獲取具有“sa”的所有結果。選擇結果后。它應該只向數據庫發送一個請求以獲取其余信息。我的腳本正在做什么:他正在發送他應該做的第一個請求。第二個請求是在與字母數量相同的時間發送。即使只有一個請求就足夠了這是我的 jQuery 代碼:$('.sucherInput').on('keyup', function () {// ** .sucherInput is the class of the input fieldvar inputValue = $('.sucherInput').val();var result      = $(".sucherres");var resultList  = $(".sucherres ul");if (inputValue.length) {  console.log(inputValue);  $.post("action/php/artikelSucher.php", {                       name: inputValue  }).done(function(data){                         // Display the returned data in browser    //console.log(data);     resultList.html(data);    result.show();  }); //.done} else{  console.log("empty");  resultList.empty();  result.hide();}$(document).on("click", ".sucherres ul li p", function(){  //set the search bar value as same as the clicked <p> tag  $('.sucherInput').val($(this).text());  //clear the Proposals list  $(resultList).empty();  $(result).hide();  //renew the value of the search bar   //since im taking the value which have to be searched in the database from the searchbar  var sucherLastIndex = $('.sucherInput').val();  console.log("Getting data from database: " + sucherLastIndex);  //load the data into the HTML file  $("#updateDiv #info").load("action/php/index-preis-liste.php", {    name: sucherLastIndex  });});});這是 Html 代碼:<div class="sucher">     <ul style="width: 100%; margin-bottom: 0;">         <li style="width: 33%;">             <input type="text" class="sucherInput" placeholder="Geben Sie einen Suchbegriff ein">         </li>     </ul>     <div class="sucherres">         <ul>            <!-- ## HERE COMES THE Proposals ## -->                   </ul>  </div>  <div id="info">  </div>
查看完整描述

1 回答

?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

我找到了解決方案**

這是通過改變

$(document).on("click", ".sucherres ul li p", function(){

$(document).off('click').on("click", ".sucherres ul li p", function(){

所以只需添加

.off('點擊')

**


查看完整回答
反對 回復 2021-11-04
  • 1 回答
  • 0 關注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號