0

Was writing a script on Email Validation using AJAX in PHP and in result I got an error:

Uncaught RangeError: Maximum call stack size exceeded at RegExp.test () at Object. (jquery.min.js:2) at Function.each (jquery.min.js:2) at jt (jquery.min.js:2) at jt (jquery.min.js:2) at jt (jquery.min.js:2) at jt (jquery.min.js:2) at Function.w.param (jquery.min.js:2) at Function.ajax (jquery.min.js:2) at (index):194

What I am trying is:

<input type="text" placeholder="Email"  id="Email" oninput="this.className = ''" name="email" required>

$(document).ready(function() {
  var email = document.getElementById("Email");
  $(email).on('keyup input', function() {
    if (email) {
      $.ajax({
        type: 'post',
        url: 'ajax_email_validation.php',
        data: {
          email: email,
        },
        success: function(response) {
          $('#email_status').html(response);
          if (response == "OK") {
            $(':button[type="button"]').prop('disabled', false);
            return true;
          } else {
            $(':button[type="button"]').prop('disabled', true);
            return false;
          }
        }
      });
    } else {
      $('#email_status').html("");
      return false;
    }
  });
});

After reading comments, I tried:

var email = document.getElementById( "Email" );
$(document).ready(function() {
 $(email).on('keyup input', function(){ 

  $.ajax({
  type: 'post',
  url: 'ajax_email_validation.php',
  data: {
   email:email,
  },
  success: function (response) {
   $( '#email_status' ).html(response);
   if(response=="OK")   
   {
    $(':button[type="button"]').prop('disabled', false);
    //return true;  
   }
   else
   {
    $(':button[type="button"]').prop('disabled', true);
    return false;   
   }
  }
  });
});
});

I am not getting any error also there is no message of response...

confused
  • 1
  • 2
  • You are making a post roundtrip to the server on each key? Why? Include a throtling at least. BTW I dont know of any `input` event you could attach to. And. You are posting the element itself, not the value of the input. – ZorgoZ Nov 24 '18 at 12:34
  • I didn't understand what are you saying... – confused Nov 24 '18 at 12:37
  • `if (email)` is useless. When you're in the event handler then there has to be an element with the id `Email` and `if (email)` will be fulfilled. Also you're sending a DOM node, wrapped in a jQuery object, to the server. The `return`s in the success handler are also useless -> [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Andreas Nov 24 '18 at 12:39
  • @ZorgoZ https://developer.mozilla.org/en-US/docs/Web/Events/input – Andreas Nov 24 '18 at 12:39
  • When a user types anything in the input box, the error is occurred... – confused Nov 24 '18 at 12:41
  • @Andreas As I am new for this codes, can you please help me with a working example by editing my codes....? – confused Nov 24 '18 at 12:44
  • @Andreas any updates...? – confused Nov 24 '18 at 13:03

0 Answers0