Variable setting

Variable setting

I am using .ajax to get the price of a product.  It returns fine.  Outside of the .ajax function, when I go to alert it, it produces an undefined.  Before the .ajax, I do a "var price;". 

  1. var price;
  2. $.ajax({ url: 'process.php',
                                data: { productID2 : product},
                                type: 'post',
                                success: function(output) {
  3.                                 if(output){
                                        price=output;
                                    }
                                }
                            });
  4. alert(price)

What would cause the price var to loose its value?