why won't my ajax work asynchronously

Posted by payling on Stack Overflow See other posts from Stack Overflow or by payling
Published on 2010-04-20T18:34:29Z Indexed on 2010/04/20 18:43 UTC
Read the original article Hit count: 249

Filed under:
|

I'm having trouble understanding why my code will not work asynchronously.

When running asynchronously the get_price.php always receives the same $_GET value even though the alert before outputs a unique $_GET value.

var arraySize = "<? echo count($_SESSION['items']); ?>"; //get items count
var pos = 0;
var pid;
var qty;

getPriceAjax();
function getPriceAjax()
{
    pid = document.cartItemForm.elements[pos].id;    //product id
    qty = document.cartItemForm.elements[pos].value; //quantity
    alert('Product: ' + pid + ' Quantity: ' + qty);

    $.ajax({
        url:"includes/ajax_php/get_price.php",
        type:"GET",
        data:'pid='+pid+'&qty='+qty,
        async:true,
        cache:false,
        success:function(data){

            while(pos < arraySize)
            {                        
               document.getElementById(pid + 'result').innerHTML=data;
                pos++;
                getPriceAjax();
            }
        }
    })  
}

© Stack Overflow or respective owner

Related posts about php

Related posts about AJAX