1
I am making an AJAX request on a route, using the Aravel, as follows:
$.ajax(
{
url: "../controle/pendentes/concluirVarias",
type: "POST",
data: { ids: arrayIds , _token: '{!! csrf_token() !!}' },
dataType: "html",
success: function(data) {
console.log(data);
}
}
);
Arrayids is an array that is declared above, getting some pushs.
The route file has the following route:
Route::group(['prefix' => '/controle'], function() {
//rota que irá marcar alguma carteirinha pendente como 'concluída'
Route::post('/pendentes/concluirVarias/', function() {
$input = Input::only('ids'); //recebe um array de ids
$input = $input['ids'];
//percorre todos os ids e seta 'pendente' = 0
foreach($input as $id) {
$aluno = new App\Aluno();
$aluno = $aluno->where('id', '=', $id)->first();
$aluno->pendente = '0';
$aluno->save();
}
});
}
No student is having the 'pending' variable changed to 0.
In the console, when I start the function that has AJAX, I have the return of an HTML of the current page.
In Network, after activating the ajax, appears 'concluirVarias' in 'name'. When I click, to see the preview, I see the current HTML page itself.
In headers, in the part of 'form Data', is passing normally the array, as I see written:
ids[]:30 ids[]:13 ids[]:17 ids[]:12 ids[]:10 ids[]:5 [ids]:3 ids[]:16 ids[]:20 ids[]:21 _token:Jg1g2upzhrmcmdcbqvdjciut8yuxn15kt0bnabro
How do I debug the route part, for example, add a dd($input) or something, so I can see what’s actually being passed to the route?
Thank you.
url: "../controle/pendentes/concluirVarias"
, is wrong as it should beurl: "/pendentes/concluirVarias/"
, that is, the path name is invalid– novic
Sorry, I didn’t put that URL in a group '/control'.
– Gabriel Augusto
Now it’s a mess because Cade the POST request? A Route::post??? Cade?
– novic
Really. It’s post.
– Gabriel Augusto
the url: "/control/pending/complete/1" or url: "/control/pending/complete/2" is thus the route then
– novic
No. /control/pending/conclusionVarias. I had not seen that I had taken the wrong part of the original code. Sorry.
– Gabriel Augusto
You can debug this part:
Input::only('ids')
. After passing this value to the $input variable typedd($input)
.– Andre Gusmao
I did that, but there was no difference in the output. It still keeps returning the whole page on the console. Funny that if I change the name of the url to one that doesn’t exist, it keeps returning the same thing.
– Gabriel Augusto