this is how i do it
controller
public function getPositions($id)
{
if (Request::ajax())
{
$positions = DB::table('sports_positions')->select('position_id','name')->where('sport_id', '=', $id)->get();
return Response::json( $positions );
}
}
ajax
/* Load positions into postion <selec> */
$( "#sport_id" ).change(function()
{
$.getJSON("/sport/"+ $(this).val() +"/positions", function(jsonData){
select = '<select name="position" class="form-control input-sm " required id="position" >';
$.each(jsonData, function(i,data)
{
select +='<option value="'+data.position_id+'">'+data.name+'</option>';
});
select += '</select>';
$("#position").html(select);
});
});
Thanks you so much @extjac , Your sample help me a lot for select option content with ajax. :)
Thank you also! This is a really good example!
You can also follow bellow good example link : http://itsolutionstuff.com/post/laravel-5-dynamic-dependant-select-box-using-jquery-ajax-example-part-1example.html
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community