[英]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.