2011-04-19 7 views
3

JSJQuery와 자동 완성 문제

$("#ethnicbg").autocomplete({ 
    source: function(request, response) { 
     $.ajax({ 
      url: 'ethnic/', 
      type: 'POST', 
      dataType: "jsonp", 
      data: { 
       q: request.term 
      }, 
      success: function(data) { 
       response($.map(data, function(item) { 
        return { 
         label: item.title, 
         value: item.value 
        } 
       })); 
      } 
     }); 
    }, 
    minLength: 1, 
    select: function(event, ui) { 
     // log(ui.item ? 
      // "Selected: " + ui.item.label : 
      // "Nothing selected, input was " + this.value); 
    }, 
    open: function() { 
     $(this).removeClass("ui-corner-all").addClass("ui-corner-top"); 
    }, 
    close: function() { 
     $(this).removeClass("ui-corner-top").addClass("ui-corner-all"); 
    } 
}); 

PHP는 그것은 데이터를 반환

header('Content-type: application/json'); 
$url = $this->url->get(); 
$arr = get_data(); // returns [{"title":"White","value":"White"}] 
echo json_encode($arr); 

, 문제는 성공에 어딘가에 : 기능, 그냥 console.log('TEST') DNT 보일 퍼트 response($.map.... 전에 전혀 거기에 가지 않거나 내가 뭘 잘못하고 있는지 알려주지?

아무것도 누군가가 JSON, JSONP의 차이를 설명 할 수있는 경우 dataType: "json",해야

dataType: "jsonp",를 해결? 이 경우에 그것은 내게 건너 올 수도있는 다른 사람들을 돕는가? 어떤 사람이 JSON, JSONP의 차이를 설명 할 수있는 경우, "JSON": "JSONP", dataType와 같아야합니다

+1

JSONP를 사용하면 요청 페이지와 다른 도메인에있는 서버에 요청할 수 있습니다. http://en.wikipedia.org/wiki/JSONP –

답변

4

데이터 유형을 해결? 이 경우에 그것은 내게 건너 올 수도있는 다른 사람들을 돕는가?