2013-07-27 2 views
0

양식의 키워드에 대한 선구자를 사용하려고하고 있는데 응답 헤더의 결과를보고 좁혀진 결과를 표시하지 않고 전체 표를 반환하고 있습니다. 그것은 모든 결과를 반환하기 전에 시간 초과가 발생했다고 생각합니다. 나는이 두 사이트에서 발견 아약스 정보와 선행 입력 사용하고 있습니다 : 1) http://www.webmaster-source.com를, 2) tatiyants.com 다음아약스 응답을 가진 부트 스트랩 유형 머리말 결과가 좁혀지지 않음

가 jQuery를/자바 스크립트 부분 여기

$('#keyword').typeahead({ 
      minLength: 1, 
      source: function (query, process) { 
       items = []; 
       map = {}; 
       $.ajax({ 
        type: 'post', 
        url: 'includes/php/get_info.php', 
        data: { type: 'keyword', q: query }, 
        cache: false, 
        dataType: 'json', 
        success: function (data) { 
         $.each(data, function (i, product) { 
          map[product.keyword] = product; 
          items.push(product.keyword); 
         }); 
         return process(items); 
        } 
       }); 
      }, 
      updater: function (item) { 
       if (jQuery.type(map[item]) !== 'undefined'){ 
        //add previously used tag 
        $('#keywords').append('<div class="remove" item="'+item+'"><span class="tag">'+item+'</span><button type="button" class="close" item="'+item+'">×</button><input type="hidden" name="ci_keywords[]" value="'+item+'"></div>'); 
       } else { 
        //add the new tag 
        $('#keywords').append('<div class="remove" item="'+item+'"><span class="tag">'+item+'</span><button type="button" class="close" item="'+item+'">×</button><input type="hidden" name="ci_keywords[]" value="'+item+'"></div>'); 
       } 
      }, 
      matcher: function (item) { 
       if (item.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1) { 
        return true; 
       } 
      }, 
      sorter: function (items) { 
       items.unshift(this.query); 
       return items; 
      } 
     }); 

것은 내 get_info.php

입니다
if(isset($_POST['type']) && $_POST['type'] == 'keyword') { 
    $keywords = $dbh->prepare("SELECT DISTINCT `keyword` FROM `ci_keywords` WHERE `keyword` LIKE ?"); 
    $keywords->execute(array('%'.$_POST['query'].'%')); 
    $results = $keywords->fetchAll(PDO::FETCH_ASSOC); 
    echo json_encode($results); 
} 
내 페이지의 HTML은

입니다 :

<div class="control-group"> 
          <label class="control-label" for="keyword">Keywords or Phrases</label> 
          <div class="controls"> 
           <input class="span4" type="text" id="keyword" placeholder="Keywords" autocomplete="off"> 
           <div id="keywords" class="clearfix"></div> 
          </div> 
         </div> 

그래서 내 탐구 이온 - 내가 보낸 검색어로 검색 범위를 좁히지 않고 전체 목록을 반환하는 이유는 무엇입니까? 당신이 보내

답변

3

변수 이름은 q입니다 : 당신이 PHP에서 검색

data: { type: 'keyword', q: query }, 

변수 이름은 query입니다 :

$keywords->execute(array('%'.$_POST['query'].'%')); 

당신이이 문제를 방지 도움이 될 오류보고 켜기.

+0

란티, 이것은 매우 당황 스럽네요! 그거였다! 나는 그것을 바르게 평가한다! – doublenit

1

문제는 PHP로 쿼리를 구성하는 데 있습니다. 검색 용어를 q으로 보내고 있지만 액세스는 query입니다. 그래서 업데이트 $_POST['query'] ~ $_POST['q']

관련 문제