why won't my ajax work asynchronously
- by payling
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();
}
}
})
}