Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9274915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:27:56+00:00 2026-06-18T16:27:56+00:00

I want to validate a field using jQuery ajax and php. When I start

  • 0

I want to validate a field using jQuery ajax and php.

When I start taping more then 3 characters it send the request to php file but my problem is when I tap 3 valid characters and the 4th is invalid I must wait for executing the request 4 times.

I want to execute only the last request and kill the other pending request

I tried:

xhr = $.ajax(//...);
xhr.abort();

and

if(typeof xhr !== 'undefined')
 xhr.abort();
xhr = $.ajax(//...);

but it doesn’t work

This is my code:

// Check validation errors
var minLength = 3;
$('input[name^="data"][type=text]').on('keyup', function(){
    var input = $(this);
    var value = $.trim(input.val());
    var url = input.data('url');
    var div = input.parent();
    var serialized = input.serialize();
    if(value.length >= minLength){
        $.ajax({
            type: 'POST',
            url: url+'.json',
            data: serialized,
            dataType: 'json',
            success: function(data){
                var error = data.error;

                if(error){
                    div.removeClass('valid').addClass('invalid');
                }else{
                    div.removeClass('invalid').addClass('valid');
                }
            }
        });
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:27:57+00:00Added an answer on June 18, 2026 at 4:27 pm

    something you could try, dont send the request if another key is pressed within a time period:

    var minLength = 3;
    var time_out_id=0;
    $('input[name^="data"][type=text]').on('keyup', function(){
        var input = $(this);
        var value = $.trim(input.val());
        var url = input.data('url');
        var div = input.parent();
        var serialized = input.serialize();
        if(value.length >= minLength){
    
            if(time_out_id != 0) clearTimeout(time_out_id);
    
            time_out_id = setTimeout(function(){
    
                time_out_id=0;
                $.ajax({
                    type: 'POST',
                    url: url+'.json',
                    data: serialized,
                    dataType: 'json',
                    success: function(data){
                        var error = data.error;
    
                        if(error){
                            div.removeClass('valid').addClass('invalid');
                        }else{
                            div.removeClass('invalid').addClass('valid');
                        }
                    }
    
                });
    
            }, 250);
    
        }
    });
    

    This wont send a request until 250ms has past since the last keypress.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate my date field in mm-dd-yyyy format using jquery validation plugin.
I'm using the jQuery Validate plugin and want to validate an input field using
I am creating a registration form using PHP and jquery with ajax. Each field
I want validate my form using jquery (the field 'name1' is required and 'email'
Actually, I want to validate the Canadian postal code form field using jQuery validation.
I'm using jQuery with PHP for form validation. I want to return the fields
I m using jquery validator plugin. i need to validate some field with some
I am using jquery validation plugin. I have an 'add file field' button which
I want my Agree To Terms checkbox to be mandatory using jQuery validate, in
I'm using the jQuery Validation Engine . I want the erroneous form field to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.