การเติมข้อความอัตโนมัติ Jquery ด้วย Laravel 4 ไม่ทำงาน

ฉันใช้การเติมข้อความอัตโนมัติ jquery กับ Laravel 4.2.13 ฉันกำลังพยายามค้นหาค่าในรูปแบบภายในโมดอล boostrap ฉันกำลังส่งค่า get และรับการตอบกลับอย่างถูกต้อง แต่การป้อนข้อความไม่ได้เติมค่าลงไป นี่คือมุมมอง create.blade.php ของฉัน

<!DOCTYPE html>
<html>
<head>
    <title>Crear Detalle</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="/th//codeorigin.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//codeorigin.jquery.com/ui/1.10.2/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="/th{{ asset('css/bootstrap.min.css') }}">
    <link rel="stylesheet" type="text/css" href="/th{{ URL::asset('css/main.css') }}" />
    <script type="text/javascript" src="{{ URL::asset('js/bootstrap.min.js') }}" ></script>

</head>

<body>

<div class="container">

<nav class="navbar navbar-inverse">
    <div class="navbar-header">
        <a class="navbar-brand" href="/th{{ URL::to('nota_detalle') }}">Panel de Detalles de Ordenes</a>
    </div>
    <ul class="nav navbar-nav">
        <li><a href="/th{{ URL::to('nota_detalle') }}">Ver todos los Detalles</a></li>
        <li><a href="/th{{ 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="/th#" 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>
                <?= Form::open(); ?>
                <?= Form::label('auto', 'Escriba el Numero de Chapa: '); ?>
                <?= Form::text('auto', '', array('id' => 'auto')); ?>
                <br />
                <?= Form::label('response', 'Codigo de la Orden: '); ?>
                <?= Form::text('response', '', array('id' =>'response', 'disabled' => 'disabled')); ?>
                <?= Form::close(); ?>
                <button type="submit" class="btn btn-primary">Search</button>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cerrar</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        $("#auto").autocomplete({
            source: "create/getdata",
            minLength: 1,
            select: function( event, ui ) {
            $('#response').val(ui.item.id);
            }
        });
    });
</script>
</body>
</html>

นี่คือไฟล์เส้นทางของฉัน:

Route::get('nota_detalle/create/getdata', 'SearchController@index');

และนี่คือไฟล์ SearchController ของฉัน

<?php

class SearchController extends BaseController {

    public function index()
    {
        $term = Str::upper(Input::get('term'));

        $results = NotaCabecera::select("codigo_nota", "chapa_vehiculo")->where('chapa_vehiculo', 'LIKE', '%'.$term.'%')->get();
        //dd($results);

        $data = array();
        foreach ($results as $result) :
            //$data[] = $result->codigo_nota.' '.$result->chapa_vehiculo;
            $data[] = array('value' => $result->chapa_vehiculo, 'id' => $result->codigo_nota);
        endforeach;

        return Response::json($data);
    }


}

นี่คือกิริยาของฉัน:

ป้อนคำอธิบายรูปภาพที่นี่

นี่คือบันทึกของฉัน:

ป้อนคำอธิบายรูปภาพที่นี่

ป้อนคำอธิบายรูปภาพที่นี่

มีปัญหาอะไร? และอีกคำถามหนึ่งว่าทำไมมันถึงใช้ไวยากรณ์ php มันไม่เหมือนกับความแตกต่างคืออะไร ?? (ฉันทำตามบทช่วยสอนสำหรับสิ่งนี้)

ขอบคุณ


person juanpscotto    schedule 02.01.2015    source แหล่งที่มา


คำตอบ (2)


ตัวอย่างนี้ใช้ได้ผลสำหรับฉันอย่างแน่นอน

// Javascript

<script type="text/javascript">
$(function(){
 $("#auto").keyup(function(){
$("#auto").autocomplete({
source:"{{URL('getdata')}}",
minLength: 3
});
$("#auto").autocomplete("widget").height(200);
 });
});
</script>
   // view

<h2>Laravel Autocomplete form Database data</h2>
{{ Form::open() }}

{{ Form::label('auto', 'Find a color: ') }}
{{ Form::text('auto', '', array('id' => 'auto'))
}}
{{form::submit('Search', array('class' => 'button expand'))}}
{{ Form::close() }}



// routes.php



Route::any('getdata', function()
{
$term = Input::get('term');
$data = DB::table("words")->where('word', 'LIKE', $term.'%')->get();
$return_array = array();
foreach ($data as $v) {
}
return Response::json(array('value' => $v->word ));
});

Github : ที่เก็บ Github

person Hashmat Waziri    schedule 12.04.2015
comment
เป็นไปได้อย่างไรที่สิ่งนี้ใช้ได้ผลสำหรับคุณ? คุณมีปุ่มค้นหา แต่ควรเติมข้อความอัตโนมัติใช่ไหม - person Vladd; 21.09.2015
comment
ลืมเขียนและมันสายไปแล้วที่จะแก้ไขความคิดเห็นของฉันด้านบน: และดูที่ foreach ของคุณใน rotes.php เหรอ? foreach ($data as $v) { } กลับ การตอบสนอง::json(array('value' =› $v-›word )); อย่างจริงจัง?? - person Vladd; 21.09.2015

เพียงนามแฝงฟิลด์ที่เลือกด้วยค่า:

$results = NotaCabecera::select("codigo_nota as value", "chapa_vehiculo")->where('chapa_vehiculo', 'LIKE', '%'.$term.'%')->get();

person Ayman Hussein    schedule 25.04.2015