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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:09:14+00:00 2026-06-12T21:09:14+00:00

I have a jQuery change event on a checkbox that makes an Ajax call,

  • 0

I have a jQuery change event on a checkbox that makes an Ajax call, and then highlights the table row that the checkbox belongs to. I’m having a problem when the Ajax call reports an error – in this case I want to reverse the checkbox click (I’m using that.prop("checked", !that.prop("checked")) to do so). However, what is happening is that it enters an infinite loop of calling the change event. As you can see, in order to stop this behaviour I’ve tried to set a variable called ajaxInProgress, but it doesn’t seem to be working as I’d hoped. Can anyone provide an alternative approach or spot the bug? I’m not sure that the way I’m resetting the checkbox is necessary – is it possible to reset the checkbox and still prevent the change event from kicking off?

var ajaxInProgress = false; //add this to stop recursive calls when errors occur 
jQuery(document).ready(function() {
  jQuery(".cc").change(function (e) {

    if (ajaxInProgress) return;

    var mode = "remove"
    if (jQuery(this).attr("checked")) {
       mode = "add"
    } 

    //grab the application ID from the checkbox ID
    var thisApp = this.id.substr(3);
    var that = jQuery(this);
    ajaxInProgress = true;
    jQuery.get("/particular/edit-ajax", { application_id: thisApp, 
                                          party_id: 1920, 
                                          party_rel_id: 21,
                                          mode: mode} , function(response) {
            if (response == 0) {
              that.closest('tr').removeClass('even').removeClass('odd').addClass('highlight');//highlight the tr
            } else {
              e.preventDefault();
              that.prop("checked", !that.prop("checked")); //reset the checkbox if there was an error
              alert("Please contact support - couldn't update database for application  "+thisApp+". Response was: "+response);
            }
    });       
    ajaxInProgress = false;
  });
});
  • 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-12T21:09:15+00:00Added an answer on June 12, 2026 at 9:09 pm

    It may be because you have ajaxInProgress = false; after you jQuery.get. This sets it to false before you even get anything back from your ajax request. Move that line to inside the callback:

    jQuery.get("/particular/edit-ajax",
        {
            application_id: thisApp,
            party_id: 1920,
            party_rel_id: 21,
            mode: mode
        },
        function(response) {
            ajaxInProgress = false;
    
            if (response == 0) {
                that.closest('tr').removeClass('even').removeClass('odd').addClass('highlight');//highlight the tr
            } else {
              e.preventDefault();
              that.prop("checked", !that.prop("checked")); //reset the checkbox if there was an error
              alert("Please contact support - couldn't update database for application  "+thisApp+". Response was: "+response);
            }
        }
    );
    

    Fiddle: http://jsfiddle.net/gromer/BgNfR/

    My Fiddle is using window.setTimeout to simulate the ajax call. I thought my solution wasn’t working, but it was because I initially used window.setInterval so it looked like it was getting called over and over again, which it was, just wasn’t simulating the ajax request as I should have been.

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

Sidebar

Related Questions

I have a jQuery event handler that reacts to every change in an: <input
I have some JavaScript/jQuery code that watches for the changed event on a checkbox:
I have jQuery that uses the change event from a selection box to update
I have a custom jQuery plugin which binds a change event to a form
I have a jQuery colorpicker that the visitor can change and I am trying
I have this jQuery script that works fine: $(select).change(function () { var finalPrice =
I have a number input that should trigger jQuery on every change. To do
I'd like to animate table body TBody change with jQuery. I have a table:
I have two ajax functions that fetch JSON objects using .getJSON and then build
I have a checkbox that I want to perform some Ajax action on the

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.