How to debug an ajax request for a route?

Asked

Viewed 276 times

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 be url: "/pendentes/concluirVarias/", that is, the path name is invalid

  • Sorry, I didn’t put that URL in a group '/control'.

  • Now it’s a mess because Cade the POST request? A Route::post??? Cade?

  • Really. It’s post.

  • the url: "/control/pending/complete/1" or url: "/control/pending/complete/2" is thus the route then

  • No. /control/pending/conclusionVarias. I had not seen that I had taken the wrong part of the original code. Sorry.

  • You can debug this part: Input::only('ids'). After passing this value to the $input variable type dd($input).

  • 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.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.