-1

I'm trying to get success event but it works only for error: event Don't know what is error.

$(document).ready(function() {
  $.ajax({
    type: "POST",
    url: "http://localhost/Register/intl-tel-input-master/next.php",
    data: {
      arguments: [fname, lname, email, Numb, pass, confirm]
    },
    dataType: 'JSON',
    complete: function(data) {
      if (('error' in data)) {
        this_form.find('.error-message').slideDown();
      } else {
        alert(data);
        this_form.find('.sent-message').slideDown();
      }
    }
  });
  // return false;
});
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • It is completely unclear what you mean. If you need to look at the error, add it: [should I use done and fail](https://stackoverflow.com/questions/10931836/should-i-use-done-and-fail-for-new-jquery-ajax-code-instead-of-success-and) - complete is deprecated: `An alternative construct to the complete callback option, the .always() method replaces the deprecated .complete() method.` – mplungjan Dec 10 '20 at 08:11
  • Are you asking about the `.ajaxSuccess()` method? https://api.jquery.com/ajaxsuccess/ – Ozgur Sar Dec 10 '20 at 08:14
  • the `complete` callback is called back with `jqXHR jqXHR, String textStatus` arguments - which is why your code, expecting `data` is failing ... use `success` and `error` callbacks - when in doubt, [read the documentation](https://api.jquery.com/jquery.ajax/) – Bravo Dec 10 '20 at 08:19

1 Answers1

0

Try to check response using done/fail:

 $(document).ready(function() {
   $.ajax({
      type: "POST",
      url: "http://localhost/Register/intl-tel-input-master/next.php",
      data: {
        arguments: [fname, lname, email, Numb, pass, confirm]
      },
      dataType: 'JSON',
      })
      .done((res) => {
        console.log(res)
      })
     .fail((res) => {
        console.log(res)
      })
    });
hencel
  • 52
  • 5