[英]Dropdown postback
我做了一个下拉菜单,但是当我想发布到特定页面时,有回发信息。 什么都没发生? 我正在使用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);
}
你确定
url: '/receiveuserinformation',
指向正确的URL? 通过使用Laravel Docs上的URL Helpers确保它
也许您应该使用类似
url: {{ url("receiveuserinformation") }}
确保始终指向正确的网址。
您的代码中似乎存在语法错误。 您需要手动发布到路线,并查看遇到的错误。 或者,如果您使用的是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.