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

  • Home
  • SEARCH
  • 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 8159003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:47:07+00:00 2026-06-06T17:47:07+00:00

I have a page with some checkboxes and a submit button. I use AJAX

  • 0

I have a page with some checkboxes and a submit button. I use AJAX to post the checkbox values to a PHP script, calc.php, run some calculations with the data and assign the result to a PHP session variable. I have another PHP script, json.php, that takes that session data and encodes it as JSON for the jquery to display in the div. My problem is I allow the user to set the amount of data sets they are going to submit, subnumber, and my display loop gets out of sync when the user changes the number of sets.

For example, if they start with 3 data sets, they submit them one by one by pressing #button. After the last set, if (count == max) runs and. Now they can do another calculation and change the number of data sets if they wish. If they change it to say 2, output goes to four instead of reseting to 1 and emptying #log.

$("#button").click(function() {
$.ajax({
  type: "POST",
  url: "calc.php",
  data: $("form#checkboxes").serialize(),
  success: function(data) {
    if(document.getElementById('calc').checked) {
    var max = checkboxes.subnumber.value;
    var stop = Number(max) + 1;
    count++;
    output++;
    $.getJSON('json.php', function(data) {
      $.each(data, function(key, val) {
        $('#log').append(output);
        $('#log').append(val.result);
        $('#log').append("</br>");
      })
    })
    if (count == max){
      count = 0;
      $("#results").load('results.php')
    }
if(output == stop) {
  $("#log").empty();
  output = 1;
}
}
}
})
}

I know it’s something simple, but I have been trying to fix it for two hours now and can’t figure out the problem. Everything else works perfectly, it’s just the output counter that isn’t done correctly.

  • 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-06T17:47:09+00:00Added an answer on June 6, 2026 at 5:47 pm

    You’re running asynchronous calls into your JSON. If users are doing things so quickly that the calls are coming back out of order, the issue lies in there.

    You’ve got two options:

    1. Run all of your JSON synchronously (use async:false in your JSON calls)
    2. Utilize a counter and only process events that are coming back on the current index.

    Psuedo Code for #2:

    var pCounter = 0;
    function doSomeAjax()
    {
        pCounter++;
        $.ajax('url',{
            data:{count:pCounter}
            success:function(data)
                {
                    // your json should return the current counter index
                    if (data.counter != pCounter) return;
                    // execute normally.
                }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web page like this: <form id=some-form> <input type='text'> <button type=submit> </form>
I have 2 checkboxes in a form and onclick of these, some php code
I have a page of checkboxes, in some cases more than 100. I'm currently
I have this login page managed in php. It contains several checkboxes, radiobuttons and
I have a page with some user selectable options and a button that, when
I have a page with some controls, usercontrols etc. when I change a div
I have a page with some HTML in it. and I need to set
I have HTML page with some HTML element with ID=logo . I need to
How to find all files in directory? I have HTML page in some directory.
I have an XML page with some elements in various languages - Arabic, English,

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.