2014-12-20 5 views
1

laravel로 twitter typeahead.js를 사용하려고하지만 작동하지 않습니다.laravel과 함께 typeahead.js 사용

doing a search

: 여기

create.blade.php 내 코드

<!-- app/views/nerds/create.blade.php --> 

<!DOCTYPE html> 
<html> 
<head> 
    <title>Crear Detalle</title> 
    <link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}"> 
    <link rel="stylesheet" type="text/css" href="{{ URL::asset('css/main.css') }}" /> 
    <script type="text/javascript" src="{{ URL::asset('js/jquery-2.1.1.min.js') }}" ></script> 
    <script type="text/javascript" src="{{ URL::asset('js/bootstrap.min.js') }}" ></script> 
    <script type="text/javascript" src="{{ URL::asset('js/typeahead.js') }}" ></script> 
</head> 
<script> 
$(document).ready(function() 
{ 
    $.ajax({ 
    type: "POST", 
     url: "http://chapincar.dev/notas_detalle/create", 
     data: "autocomplete="+$("input[name=autocomplete]").val(), 
     success: function(data) 
     { 
      json = $.parseJSON(data);//parseamos el json 
      var codigo = json 
      console.log(codigo) 

      $('#remote .typeahead').typeahead({ 
       minLength: 3, 
       highlight: true, 
      }, 
      { 
       name: 'codigo', 
       source: codigo 
      }); 

     }, 
     error: function(data) 
     { 
      json = $.parseJSON(data);//parseamos el json 
      var error = json 
      console.log(error) 
     } 
    }); 
}); 
</script> 
<body> 

<div class="container"> 

<nav class="navbar navbar-inverse"> 
    <div class="navbar-header"> 
     <a class="navbar-brand" href="{{ URL::to('nota_detalle') }}">Panel de Detalles de Ordenes</a> 
    </div> 
    <ul class="nav navbar-nav"> 
     <li><a href="{{ URL::to('nota_detalle') }}">Ver todos los Detalles</a></li> 
     <li><a href="{{ URL::to('nota_detalle/create') }}">Crear un Detalle</a> 
    </ul> 
</nav> 


<h1>Crear Detalle</h1> 

<!-- if there are creation errors, they will show here --> 
{{ HTML::ul($errors->all())}} 

{{ Form::open(array('url' => 'nota_detalle', 'class' => '')) }} 

    <table> 
     <tr> 
      <td class="ancho"> 
       <div class="form-group"> 
        {{ Form::label('codigo_nota', 'Codigo Orden') }} 
        {{ Form::text('codigo_nota', Input::old('codigo_nota'), array('class' => 'form-control')) }} 
       </div> 
      </td> 
      <td class="ancho"> 
       <a href="#" class="btn btn-default" 
        data-toggle="modal" 
        data-target="#modalCliente">Buscar</a> 
      </td> 
     </tr> 
     <tr> 
      <td class="ancho"> 
       <div class="form-group"> 
        {{ Form::label('cantidad_detalle', 'Cantidad') }} 
        {{ Form::text('cantidad_detalle', Input::old('cantidad_detalle'), array('class' => 'form-control')) }} 
       </div> 
      </td> 

     </tr> 
     <tr> 
      <td class="ancho"> 
       <div class="form-group"> 
        {{ Form::label('descripcion_detalle', 'Descripción') }} 
        {{ Form::textarea('descripcion_detalle', Input::old('descripcion_detalle'), array('class' => 'form-control')) }} 
       </div> 
      </td> 
     </tr> 
     <tr> 
      <td class="ancho"> 
       <div class="form-group"> 
        {{ Form::label('precioIVA_detalle', 'Precio con IVA') }} 
        {{ Form::number('precioIVA_detalle', Input::old('precioIVA_detalle'), array('class' => 'form-control')) }} 
       </div> 
      </td> 
     </tr> 
     <tr> 
      <td class="ancho"> 
       <div class="form-group"> 
        {{ Form::label('precioSinIVA_detalle', 'Precio sin IVA') }} 
        {{ Form::number('precioSinIVA_detalle', null, array('class' => 'form-control', 'size' => '30x4')) }} 
       </div> 
      </td> 
     </tr> 
     <tr> 
      <td class="ancho"> 
       <div class="form-group"> 
        {{ Form::label('precioTotal_detalle', 'Precio Total') }} 
        {{ Form::number('precioTotal_detalle', null, array('class' => 'form-control')) }} 
       </div> 
      </td> 
     </tr> 
    </table> 

    {{ Form::submit('Agregar Detalle!', array('class' => 'btn btn-primary')) }} 

{{ Form::close() }} 

<!-- Modal --> 
<div class="modal fade" id="modalCliente" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true"> 
    <div class="modal-dialog modal-lg"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&amp;times;</button> 
       <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
      </div> 
      <div class="modal-body"> 
       <div class="form-group remote"> 
        <label for="query">Search:</label> 
        <input class="form-control" name="autocomplete" id="autocomplete" placeholder="Start typing something to search..." type="text"> 
       </div> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cerrar</button> 

      </div> 
     </div> 
    </div> 
</div> 
{{Form::close()}} 
</div> 
</body> 
</html 

>

이 내 routes.php 파일

Route::post("nota_detalle/create", function(){ 
    $search = Input::get("autocomplete"); 
    $query = DB::table("notas_cabecera")->where('chapa_vehiculo', 'LIKE', '%'.$search.'%')->get(['codigo_nota']); 
    Response::json($query); 
}); 

이 내 오류 로그입니다입니다입니다

https://www.dropbox.com/s/1li3hhylw7ukbv0/Imagen%202.png?dl=0

는 서버 측에서 @Loz Cherone의 의견에 따라 그래서

+0

디버깅하기 위해 할 일이 많을 수 있습니까? serverside는'querya ... '가 아닌'typeahead = ...'가 아닌 jQuery의 오류도 있습니다 : function (data) {console .log (데이터); ... '? –

답변

-1

을 제발 도와 드릴까요 :

JSON errors

post data

answer 내 데이터베이스입니다 나는 패러미터가 012 인 laravel 라우터에있다.. 다른 것은 수동으로 echo json_encode를 사용하는 것입니다. 내장 된 laravel 함수 return Response::json($query);을 사용하면이 파일을 조금 더 깨끗하게 사용하지 않고 라우트 파일에서 echo를 사용하지 않을 것입니다. laravel 응답에 대한 추가 정보 - http://laravel.com/docs/4.2/responses#special-responses

문제가 더 많은 경우 브라우저에서 콘솔을 확인하여 자세한 내용을 확인하십시오.

+0

내 코드가 바뀌지 만 ir가 작동하지 않습니다. 제발 도와주세요, 오류 로그를 상단에 넣습니다. – juanpscotto

+0

어떤 버전의 laravel을 사용하고 있습니까? '작곡가 업데이트 '를 해본 적이 있습니까? – clonerworks

+0

나는 이미 그렇게 해왔다. 4.3.16 버전의 laravel을 사용하고 있습니다. – juanpscotto

관련 문제