I'm trying to update a section of my page using this code. I have a select element #sModelo that every time that it changes, updates a table that i have. The problem is that when i change the select the load function receives http://localhost:8000/admin/auditorias/pesquisa/+idModelo+" instead of http://localhost:8000/admin/auditorias/pesquisa/1 (1 is the value from idModelo)
Route:
Route::get('admin/auditorias/pesquisa/{idModelo}', array('uses' => 'PerguntaController@getBlocosPergunta', 'as'=>'pergunta.pergunta'));
Blade code:
<div class="form-group @if ($errors->has('modelo')) has-error @endif">
<select id="sModelo" name="modelo" class="form-control" style= "width: 150px">
<option value="" disabled selected> Modelo </option>
@foreach ($modelos as $modelo)
<option value="{{$modelo->id }}"> {{$modelo->nome }}</option>
@endforeach
</select>
</div>
...
<table id="updateTabelaPerguntas" class="table table-bordered table-condensed alinhar">
@include('pergunta.pergunta')
</table>
Jquery code:
$("#sModelo").on('change', function(e){
var idModelo = e.target.value;
console.log(idModelo); //shows the value 1
$('#updateTabelaPerguntas').load('{{ URL::action("PerguntaController@getBlocosPergunta",array("idModelo"=>'+idModelo+')) }}');
});
Controller:
public function getBlocosPergunta($idModelo)
{
return View::make('pergunta.pergunta', array('blocos'=>Pergunta::getBlocosPergunta($idModelo)));
}