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. 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
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? Make sure of it by using the URLs Helpers on Laravel Docs
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.
// 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'));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.