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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:21:05+00:00 2026-06-12T23:21:05+00:00

I am having trouble when trying to implement a delay to a jQuery loop

  • 0

I am having trouble when trying to implement a delay to a jQuery loop function (.each).
The problem is: I have a list of rows with multiple columns, where the user needs to enter his data.
Now when the user clicks on a button save, all rows needs to be retrieved one by one and their data inserted in a database.

1st get inserts the data and return the last inserted id. Then in the second $.get that last inserted id is used as a history entry.

The code below works as it should, the only problem is the whole procedure is being finished before the nested $.get starts. So all data inserted by the second $.get is the same.

The function getIdNumber removes unwanted characters from the id (ex from row_1 to 1)

$('.data_row').each(function(i){
    id = getIdNumber(this.id);

    setTimeout(function() {

    date = $('#dat_'+id).val();
    customer = $('#cus_'+id).val();
    amount_paid = $('#amt_'+id).val();
    remarks = $('#rem_'+id).val();
    account = $('#acc_'+id).val();

       url = "bin/_receipts.php?addreceipts=&date="+date+"&customer="+customer+"&amountpaid="+amount_paid+"&remarks="+remarks+"&paidaccount=" + account;

       $.get(url, function(d){

          url2 = "bin/_ledgerHandler.php?addaudittrail=&user="+escape("<? echo $_SESSION["user_id"]; ?>")+"&trantype="+escape("Receipt - "+d+"")+"&val="+escape(amount_paid)+"&category=receipts";
          $.get(url2, function(){  

          });                    

       });         

    }, 1000*i);

 });
  • 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-12T23:21:06+00:00Added an answer on June 12, 2026 at 11:21 pm

    For your second $.get, rather than using the values you calculated before the first get, you need to include everything the second $.get needs in the data result of the first get. That way you can guarantee that all the data for the second $.get is relevant to the result of the first.

    In other words, don’t use the values of amount_paid in you second $.get, instead return any needed values in your data along with the last insert id.

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

Sidebar

Related Questions

I'm trying to implement my own list class but am having trouble reversing just
I am trying to implement an MVC3 DatePicker but having trouble. I have the
I'm having trouble trying to implement a linked List without using classes(we're not there
I'm trying to implement picking using Pyglet's OpenGL wrapper, but I'm having trouble converting
I'm having trouble; I'm trying to implement a cinema booking system however I cannot
i'm having trouble trying to define this function-like macro, which takes 4 vector magnitudes
I'm having trouble trying to use a function in a javascript file I've included
I'm trying to implement the Ford Fulkerson Algorithm in C++. However, I'm having trouble
I having some trouble trying to figure out how to implement a Rails 3
I'm trying to implement the XHR streaming Comet technique in jQuery, but am having

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.