Are you sure the data is coming back the way you expect? Put an alert (data) in the callback function.
On May 13, 3:02 am, V <vincenti...@gmail.com> wrote: > I can't get global variables work, maybe somebody knows the answer > because this should be very simple. > > The following does not work, the price is not available at the end of > the function in the alert. > > function calc_matrix(x, y) > { > loc = "index.php?module=product"; > > var price = 0; > $.post(loc, > { > "request":"xmlhttp", > "action":"calc_pricematrix", > "x":x, > "y":y > }, > function(data) > { > price = Math.round(parseFloat(data)*100)/100; > > }); > alert(price); > > }