简体   繁体   English

下拉回发

[英]Dropdown postback

I´ve made a dropmenu but when I want to post to a specific page when there is a post back. 我做了一个下拉菜单,但是当我想发布到特定页面时,有回发信息。 Nothing happens? 什么都没发生? I'm working with the laravel framework. 我正在使用laravel框架。 This is my code: 这是我的代码:

@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>

In my console are now errors? 现在在我的控制台中有错误吗?

EDIT 编辑

This is my routes file 这是我的路线文件

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

This is my 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);
    }

Are you sure that 你确定

url: '/receiveuserinformation',

is pointing to the right URL? 指向正确的URL? Make sure of it by using the URLs Helpers on Laravel Docs 通过使用Laravel Docs上URL Helpers确保它

Maybe you should use something like 也许您应该使用类似

url: {{ url("receiveuserinformation") }}

to be sure to point always to the right url. 确保始终指向正确的网址。

It looks like there are syntax errors in your code. 您的代码中似乎存在语法错误。 You need to post to the route manually and see what errors you get. 您需要手动发布到路线,并查看遇到的错误。 Or if you are using a browser like Chrome you can see the response that the ajax call is getting back with the Developer Tools. 或者,如果您使用的是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'));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM