2011-10-19 2 views
0

에서 현재 텍스트를 얻을 방법을 잘 :의 jQuery 자동 완성 기능 - 나는 현재 내 자동 완성 jQuery 코드에서 이런 일이 필드

$("input#autocomplete").autocomplete({ 
    source: "/problems/get_categories_ajax.php?category="+$(this).data("autocomplete", ui.item.autocomplete), 
    delay: 0, 
    minLength: 0, 
    autoFocus: true, 
    select: function (event, ui) { 
      $("#user_id").val(ui.item.id); 
      $(this).data("user_id",ui.item.id);//Store arbitrary data associated with the specified element 
      $(this).data("username",ui.item.value);//Store arbitrary data associated with the specified element 

    }, 
     selectFirst: true, 
     autoFill: true, 
     mustMatch: true 
}) 
.bind("blur",function() { 
    var autocomplete = $(this).data("autocomplete"); 

    $(this).val(autocomplete); 
    $("#autocomplete").val(autocomplete); 
});  

하지만 난 때 UI를 변수를 사용할 수 없습니다 오류 여기에 AJAX 호출을 작성하려고합니다. source : "/problems/get_categories_ajax.php?category="+$(this).data("autocomplete", ui.item.autocomplete),

어떻게 값을 얻을 수 있습니까? 거기서 지나가는 양식 에서요?

감사합니다.

+0

'$ (이) .DATA ("자동 완성" ui.item.autocomplete)'데이터 = 자동 완성 값을 설정하고, 그것을 검색하지 않습니다. – Joe

+0

있습니다. 나는 단지 내가 완전히 이해하지 못하는 모범에서 일하고있다. 이런 종류의 일을 어떻게 작동 시킬지에 대한 지침을 얻기를 바랬습니다. – GeekedOut

답변

0

수동으로 매개 변수로 추가 할 필요는 없습니다. 자동으로 term으로 추가됩니다.

다른 매개 변수 이름을 지정해야 할 경우, 사용자 정의 source 함수를 선언해야합니다 :

$("#city").autocomplete({ 
    source: function(request, response) { 
    $.ajax({ 
     url: "http://gd.geobytes.com/AutoCompleteCity", 
     dataType: "jsonp", 
     data: { 
     q: request.term 
     }, 
     success: function(data) { 
     response(data); 
     } 
    }); 
    } 
}); 

(출처 : http://jqueryui.com/autocomplete/#remote-jsonp)