Force error return in ajax

Asked

Viewed 363 times

1

For example when entering the client (in PHP) validate if age is above 18, before inserting, validate with a condition, and if you enter return an error, which in ajax, could be type:

 success: function (data) {
      alert('Sucesso');
 },
 error: function (data) {
      alert('Ocorreu um erro, verifique a idade informada!');
 }
  • The ajax error is for errors in the link, not for "status". Sends a variable to PH via data of that callback success and depending on that date alerts the correct content.

1 answer

0


The sucess ajax is for cases where ajax has completed its execution correctly, sending/receiving data from the server and the error is activated when any HTTP problem occurs(example, error 500).

If you want to do an age validation you can return a json in the backend with "error": "error message" or in case of success "success message", then you would perform the front check by parameter sucess ajax.

Browser other questions tagged

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