下拉回发

时间:2015-09-06 10:02:23

标签: javascript jquery laravel

我做了一个dropmenu但是当我想要回帖时发布到特定页面。什么都没发生?我正在使用laravel框架。这是我的代码:

@extends('master')
@section('title', 'Create a new ticket')

@section('content')

 <script>
 $(document).ready(function () {
    var xhr;
    });
    $("#test").change(function(e) {

    csrf = $("#token").attr('content')
    option = $(this).val();

      $.ajax({
          url: '/receiveuserinformation',
          type: 'POST',
          data: { option_id: option },
          beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', csrf);},
          success: function(result) {
              $("#kilometersprive").val(result);
          }
      });
  });
</script>


 <div class="form-group">
                        <label for="content" class="col-lg-2 control-label">Standaard route</label>
                        <div class="col-lg-10">
                                <select class="form-control input-sm" name="test" id="test">
                                @foreach($standaardroute as $route)
                                    <option value="{!! $route->id !!}">{!! $route->van !!} - {!! $route->naar !!}</option>
                                @endforeach
                                </select>               
                        </div>
                    </div>

在我的控制台中现在出错了吗?

修改

这是我的路线档案

Route::post('/receiveuserinformation','route@createroute');

这是我的路线@ createroute

 public function createroute(Request $request)
    {
        $karakterrit = karakterrit::all();
        $foundroute = standaardroute::whereId($request->all())->firstorFail();
        $standaardroute = standaardroute::all();

        return view('ritten.create',compact('karakterrit',$karakterrit))->with('foundroute',$foundroute)->with('standaardroute',$standaardroute);
    }

2 个答案:

答案 0 :(得分:1)

你确定吗

url: '/receiveuserinformation',

指向正确的网址?使用URLs Helpers on Laravel Docs

确保它

也许你应该使用像

这样的东西
url: {{ url("receiveuserinformation") }}

确保将始终指向正确的网址。

答案 1 :(得分:0)

您的代码中似乎存在语法错误。您需要手动发布到路线并查看您获得的错误。或者,如果您使用Chrome之类的浏览器,则可以看到ajax调用通过开发者工具获取的响应。

// Remove the optional id parameter as you don't need it if you are POSTing it.
Route::post('/receiveuserinformation','route@createroute');

// Remove $id as you don't need it, and replace it with the request
public function createroute(Request $request)
{
    // Get the id from the POST data
    $id = $request->input('option_id');

    $karakterrit = karakterrit::all();

    // You should really catch this exception if there isn't a matching id
    $foundroute = standaardroute::whereId($id)->firstorFail();

    $standaardroute = standaardroute::all();

    return view('ritten.create', compact('karakterrit', 'foundroute', 'standaardroute'));
}