Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    send array multiple times using ajax but I can't use back the same variable

    Emm not sure how I can describe my problem. I get the number of product ids from a class and create a for loop:

    var product_ids= document.getElementsByClassName("product_id");
            for(var i=0; i<product_ids.length; i++)
    The I send each product id one by one using ajax

    var product_id= product_ids[i].innerHTML;
                    url: "check_last_timer.php",
                    type: "post",
                    data: {product_id: product_id},
                    success: function(end_time){
    Problem is within the success function I can't use the var product_id anymore, it always shows the last product id. But I really need to use it as I need to do something like this:


    This is to update each individual div id. Eg, timer1, timer2 and so on. But what I got was the last product id all the time it loops. What I want is for it to start at timer1, timer2 and so on and not timer 10, timer10.... Please advice. Below is my php file:

    PHP Code:

    include "connect.php";
    $product_id$_POST['product_id'];//tested at ajax
    $query"SELECT * FROM product WHERE product_id='$product_id' ";
    $end_timestrtotime($end_time); //unix_time
    $nowtime(); //unix time
    $diff$end_time $now;
    $hour floor($hour);
    $min %= 60;
    $sec $diff 60;

    $hour<|| $hour==0){

    $hour<10 && $hour>0){
    $hour '0'.$hour;

    $min<|| $min==0){

    $min<10 && $min>0){
    $min '0'.$min;

    $sec<|| $sec==0){

    $sec<10 && $sec>0){
    $sec '0'.$sec;
    Last edited by jaylimixx; 06-30-2012 at 05:17 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts