Citizen
Citizen

Reputation: 12957

Return bad Laravel token error in JSON?

I'm using Dropzone for multiple image uploads. If I get a server error that returns "Whoops, there's been an issue" the on-hover error message for that ajax upload flips out and tries to display the html for the entire page. What I need is for that page to return a json message instead. Is there a way for me to catch any errors that occur on upload failure?

Upvotes: 0

Views: 85

Answers (1)

Muhaimin
Muhaimin

Reputation: 1643

you have to include the CSRF token. Normal jquery ajax can have this appended to header on body request parameter

$.ajax({
     type: "POST",
     url: "file",
     data: { 
        _token: $('input[name="_token"]').val()
     }
}).done(function( msg ) {
    console.log( msg );
});

Upvotes: 1

Related Questions