I have two connected <select>
. The first one is static,the second one is depends of the first select value. I have a problem:http://localhost/ajax-model?make_id=8 404 (Not Found)
The page where is the two select.
{{Form::open(array('url'=>'','files'=>true))}}
<div class="form-group">
<label for="make">Make</label>
<select class="form-control input-sm" name="make" id="make">
@foreach($make as $makes){
<option value="{{$makes->id}}">{{$makes->title}}</option>
}
@endforeach
</select>
</div>
<div class="form-group">
<label for="model">Make</label>
<select class="form-control input-sm" name="model">
<option value=""></option>
</select>
</div>
{{Form::close()}}
<script>
$('#make').on('change', function(e){
console.log(e);
var make_id=e.target.value;
//ajax
$.get('/ajax-model',{make_id:make_id},function(data){
//succes data
console.log(data);
alert(data);
});
});
</script>
In a route:
Route::get('/ajax-model',function(){
$make_id=Input::get('make_id');
$model=CarModel::where('make_id','=',$make_id)-get();
return Respone::json($model);
});
In a CarModel class:
class CarModel extends Model
{
protected $fillabe=['make_id','title'];
}
I read a lot about that one,and everybody say,the CSRF_token
,I added to the layout:
<meta id="token" name="token" content="{{csrf_token()}}">
So,any idea?
first error is your passing url, you should change it like-
$.get('{{url('/')}}/ajax-model',{make_id:make_id},function(data){
//succes data
console.log(data);
alert(data);
});