Are you definitely hitting this code?
Open your browser inspector tool and look in the network tab. Post the form then check the response. You should see the response code and any message.
I'm doing an AJAX POST of a simple HTML form using JQuery on my front end, to my Laravel back end, and upon success want to return the correct response to trigger JQuery's $.ajax() 'success' block rather than it's 'error' block. Unfortunately whatever I try seems to trigger the 'error' block.
My route is:
Route::post('/signup', 'AccessController@signup');
Back end:
public function signup()
{
[main code]
return response('OK', 200); // I also tried return response('OK', 200)->header('Content-Type', 'text/plain'); and just: return "OK";
}
Front end:
$('#signupbtn').click(function(e)
{
$.ajax({
headers: { 'X-CSRF-TOKEN': $('#signup-form > input[name="_token"]').val() },
type: 'POST',
url: 'signup',
data: { email: $('#email').val(), name: $('#name').val() },
dataType: 'json',
success: function (data)
{
console.log(data);
$('#signupmodal').modal('hide'); // Close sign up modal
$('#thanksmodal').modal(); // Open thanks modal
},
error: function (data)
{
console.log('Error:', data.responseText);
}
});
});
Also, if I DO want to trigger the $.ajax() 'error' block, what's the correct Laravel code for that?
Thanks.
Please or to participate in this conversation.