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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:10:22+00:00 2026-06-06T20:10:22+00:00

function check_timer(){ //get product ids var product_ids= document.getElementsByClassName(product_id); //create for loop for(var i=0; i<product_ids.length;

  • 0
function check_timer(){
    //get product ids
    var product_ids= document.getElementsByClassName("product_id");
    //create for loop
    for(var i=0; i<product_ids.length; i++){
        var product_id= product_ids[i].innerHTML;

        $.ajax({
            //send product id to check
            url: "check_last_timer.php",
            type: "post",
            data: {product_id: product_id},
            success: function(end_time){
                //trying to get product_id here

                //$("#timer"+product_id).html(end_time);
            }
        })

    }

}

I am trying to get my product id within the success function. As you can see I have a for loop that sends product_id e.g, 1,2,3…10 to “check_last_timer.php” each time it runs. Problem is how can I get back 1,2,3…10 within the success function. Each time the for loop runs, I get the last product id which is 10.

  • 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-06T20:10:24+00:00Added an answer on June 6, 2026 at 8:10 pm

    You can’t use a loop variable declared outside a closure from within that closure.

    As you’re using jQuery, use .each:

    function check_timer() {
        $('.product_id').each(function() {
            var product_id = this.innerHTML;  // or $(this).html()
            $.ajax({
                //send product id to check
                url: "check_last_timer.php",
                type: "post",
                data: {product_id: product_id},
                success: function(end_time){
                    $("#timer" + product_id).html(end_time);
                }
            });
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(document).ready(function() { //Check City Value var city_value = parseInt($(#city).val()); if( city_value == 0) {
var timeoutId; function getenginedetails(){ $.get('engine.php', function(enginedata) { $('#detailsoutput').html(enginedata); }) timeoutId = setTimeout(getenginedetails, 5000); }
I have used Javascript onlaod like this: function check() { var pic = new
i want to get the value of this td my code function check() {
I have created this function to check abecedarian with while loop (A word is
I'm writing an AJAX function that returns some information to display in a <div>
I'm trying to get my first ever trigger and function to work, but how
After adding this short js code: $(document).ready(function() { //check to see if it's an
I know which using the GetForegroundWindow function i can get the current active window
In my code here: var manTimer:Timer = new Timer(1700,5); manTimer.addEventListener(TimerEvent.TIMER, moveMan); function moveMan(e:TimerEvent):void {

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.