2016-10-10 03:33
浏览 28

Laravel AJAX表格(接收数据关注)

I have an issue recieving the data from a form which was modified with AJAX.

I have 2 fields: Cinema and Session.

The Session field updates automatically based on which cinema you have chosen. However, when I try to get the session field's value in my controller, it returns as "" (blank) where-as I want it to return what is actually displayed in the drop down box in the form.



$('#cinema').on('change', function(e){
    var cinema_id =;

    $.get('{{ url('/ajax-subcat') }}?cinema_id=' + cinema_id, function(data){
    //success data
    $.each(data, function(index, subcatObj){
        $('#sesh').append('<option value="''">'+subcatObj.session_time+'</option>');;


public function cart()
    $formData = array(
        'cinema'  => Input::get('cinema'),
        'sesh'  => Input::get('sesh'),
        'ticketType' => Input::get('ticketType'),
        'count' => Input::get('count')
    $cinemaDetails = Cinema::find($formData['cinema']);
    $session = Session::find($formData['sesh']);
    return view('movies/ticketpage/cart')
        ->with('formData', $formData)
        ->with('cinemaDetails', $cinemaDetails)
        ->with('session', $session);

View/Blade file:

<div class="container">
    <div class="row">
        <div class="col-sm-4">
            <img src="/WDAAssign2/Assign2-A/{{ $movie->image }}" height="200" width="150">
            <p>{{ $movie->description }}</p>
        <div class="col-sm-4">
        <h2>Purchase tickets!</h2>
        {!! Form::open(array('action'=>'MoviePageController@cart', 'files'=>true)) !!}
                <label>Select a Cinema:</label><br>
                <select id = "cinema" name = "cinema">
                    @foreach ($cinemas as $cinema)
                        <option value="{{$cinema->id}}">{{$cinema->name}}</option>
                <label>Select a session:</label>
                <select id = "sesh" name = "sesh">
                    <option value=""></option>
                <label>Type of ticket:</label>
                <select id= ="ticketType">
                    <option value="adult">Adult</option>
                    <option value="concession">Concession</option>
                    <option value="children">Children</option>

                <label>Number of tickets:</label><br>
                <select id = "count" name ="count">
                    @for ($i = 1; $i < 10; $i++)
                        <option value="{{$i}}">{{$i}}</option>
                <input type="submit" value="Submit">


Route::post('/movie/ticketpage/cart', 'MoviePageController@cart');
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

相关推荐 更多相似问题