在更改时动态填充选择标记

时间:2016-02-26 09:03:01

标签: php jquery laravel-5.2

我正在寻找一种方法来通过选择另一个选择标记中的值来影响另一个选择标记。当我这样做时,我收到此错误:

  

获取http://localhost/laravel/public/select?vestiging=Lichtenvoorde 500   (内部服务器错误)。

谢谢

home.blade.php

@extends('layouts.app')

@section('content')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
    window.onload = function()
    {
        var select_vestiging = $('#sel1');
        select_vestiging.change(function() {
            var vestiging = $('#sel1').val();
            $.get( "select?vestiging="+vestiging, function( data ) {
                console.log(data);
            });
        });
    }
</script>
<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">Gegevens invullen</div>

                <div class="panel-body">
                    <select class="form-control" id="sel1">
                        <option selected >Selecteer een vestiging</option>
                        @foreach ($vestigingen as $vestiging)
                            <option value='{{ $vestiging -> Plaats }}'>{{ $vestiging -> Plaats }}</option>
                        @endforeach
                    </select>
                    </br>
                    <select class="form-control" id="sel2">
                      <option selected >Selecteer een center</option>
                        @if (!empty($centers))
                                @foreach ($centers as $center)
                                    <option value='{{ $center }}'>{{ $centers }}</option>
                                @endforeach
                        @endif
                    </select>
                    </br>
                    <select class="form-control" id="sel3">
                    </select>
                    </br>
                    <select class="form-control" id="sel4">
                    </select>
                    </br>
                    <select class="form-control" id="sel5">
                    </select>
                    </br>
                    <select class="form-control" id="sel6">
                    </select>
                    </br>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

homeController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Input;
use DB;
use View;
use App\Http\Requests;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $vestigingen = DB::table('vestigingen')->distinct()->get();

        return View::make('home', compact('vestigingen'));
    }

    public function select(Request $request)
    {
        //$centers = $request->input('vestiging');

        $centers = [
            "1","2","3","4","5"
        ];

        return View::make('home', compact('centers'));

    }
}

route.php

    Route::group(['middleware' => 'web'], function () {

    Route::auth();

    Route::get('/home', 'HomeController@index');
    Route::get('/select', 'HomeController@select');
});

0 个答案:

没有答案