vendredi 6 juillet 2018

How to detect JSON object?

Can I detect a JSON object and according to its object show a message?

I tried like this but it is not working :(

$.ajax({
    type: "POST",
    url: example.php,
    data: form_data,
    success: function(data) {

      if(data.has("error")){
          alert('Invalid data')
      } else {
          alert('Correct data')  
      };

    }
});

If the data entered is wrong, data shows in the console something like this:

{"object":"error","type":"wrong_number"...

If this object contains error, I want to show error message. Otherwise, continue

Aucun commentaire:

Enregistrer un commentaire