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 ...
>

Reply via email to