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 8763217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:43:51+00:00 2026-06-13T15:43:51+00:00

When the city input field is blurred I get somnething via an ajax request

  • 0

When the city input field is blurred I get somnething via an ajax request and set that as the value of a hidden field in the same form that the city field resides in.

$('input#city').on('blur', function() {
    $.ajax({
        url: 'get/something?param=val',
        success: function(response) {
            $('input:hidden[name="something"]').val(response);
        }
    });
});

If the user submits the form immediately after blurring off the city field sometimes due to latency the hidden field is not populated because the SQL on the other end is taking too long.

The form that both these fields are in is also submitted via ajax:

$('form#find-users').on('submit', function() {
    if(NO_AJAX_CURRENTLY_RUNNING_ON_PAGE) {
        // do stuff
    }
});

How to detect if no ajax is running on the page? This will ensure that the city ajax was completed and the hidden field populated before the form is processed.

EDIT

Actually it won’t, it will only prevent the form from being submitted. But if I can detect that then I can use a setInterval and keep trying to run that code until it runs because ajax is complete. Ideally there will be something in jQuery that waits until other ajax is complete and then submits.

  • 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-13T15:43:52+00:00Added an answer on June 13, 2026 at 3:43 pm

    Use jQuery’s Ajax Events. As long as all of your Ajax calls are generated using jQuery, you have a way of knowing if any Ajax calls are outstanding.

    $(document).ready(function() {
        var ajaxBusy = false;
    
        $(document).ajaxStart( function() { 
            ajaxBusy = true; 
        }).ajaxStop( function() {
            ajaxBusy = false;
        });
    });
    

    Edit:

    So that answers your direct question about “How do I know if there is any Ajax call running.”

    Alternatively, you could disable the form’s submit buttons when run your blur handler, and then re-enable it when you’re done.

    $('input#city').on('blur', function() {
        var submit = $(this).closest('form').find(':submit:enabled');
        submit.prop('disabled', true);
        $.ajax('get/something?param=val').done(function(response) {
            $('input:hidden[name="something"]').val(response);
        }).always(function() {
            submit.prop('disabled', false);
        });
    });
    

    Edit 2:

    So now we’re at the point where we would like to delay the form submission until all current Ajax calls have completed. We let people click on the submit button, but if there are pending Ajax calls we don’t do anything right away.

    We can use a Deferred object to help us with this.

    $(document).ready(function() {
        var ajaxDefer = $.Deferred().resolve();
    
        $(document).ajaxStart( function() { 
            ajaxDefer = $.Deferred(); 
        }).ajaxStop( function() {
            ajaxDefer.resolve();
        });
    
        $('form#find-users').on('submit', function() {
            ajaxDefer.always(function() {
                // Code here will always be executed as soon as there are no 
                // Ajax calls running.
                // this points to the deferred object (ajaxDefer), so use the closure
                // to carry over any variables you need.
            });
        });
    });
    
    1. When we’re just starting out, we set up our ajaxDefer object in a resolved state. That means any functions attached using .always() will execute immediately.

    2. When the first Ajax call starts, we replace the old ajaxDefer object with a new one that has not been resolved. Any new functions attached using ajaxDefer.always() will be deferred until later.

    3. When the last Ajax call completes, we call ajaxDefer.resolve(), which causes any unexecuted deferred functions to execute. Now we’re back to our initial state, where any newly-attached functions will execute immediately.

    4. When somebody tries to submit the form, create an anonymous function that does the work and attach it to ajaxDefer. It will get executed when appropriate, depending on if there are any outstanding Ajax requests or not. Be mindful of your closures.

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

Sidebar

Related Questions

I have some input text field in a form that have name with this
I have an input field that is for City, State (two letter) and ZIP
I have an input field that is rendered with a template like so: <div
I'm trying to use geopages.org api to populate a city input field onblur of
I have the following code that basically is a input form as I have
On my FORM , for some reason, I can get my form input variable
It doesn't look like the input that FB uses for current city and hometown
I'm using an JQuery UI Autocomplete field that is tied to an ajax lookup
I have a codeigniter webform, I want to input city/state details from the user,
In the settings.php i have some input for the realname,hobby,city and select tag for

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.