But does it work with async set to false? The code should work correctly if you have async set to false. However, you cannot do this (return the JSON from the function) properly without that setting set to false.
By the way, is it suppose to be: result = price; ? I don't see what you're doing with the price variable in there. On Mar 4, 3:43 pm, Charles Liu <charles.li...@gmail.com> wrote: > hi Adwin, > it is "undefined" because it runs before ajax is finished. > maybe you should try to move "return result" next to the position of "result > = data" > > let me know if it works > > Charles > > 2009/3/5 Adwin Wijaya <adwin.wij...@gmail.com> > > > > > Hi, > > > can i have callback function on the $.ajax ? > > I don't want to use async since it will block the browser ... so can i > > use callback instead ? > > > I would like to have function that return json like this > > > function getGoodsDetail(id,member){ > > var result ; > > $.ajax({ > > type: "POST", > > url : "/goods/detail/", > > data : "id="+id, > > dataType: "json", > > async:false, > > success : function(data){ > > var price = 0 ; > > if(member == 'Y'){ > > price = data.priceMember ; > > }else{ > > price = data.priceNonMember; > > } > > // I want to return data to user > > result = data > > } > > }); > > return result; // --> always undefined > > } > > > so when I call getGoodsDetail(id, membership) it will return json > > value ... > >