0
var POS = {

PriceLookUp: function (SKU) {
            $.ajax({
                type: 'GET',
                data: 'SKU=' + SKU,
                url: '@Url.Action("GetProduct", "POS")',
                success: function (data) {
                    if (data["found"] == "true") {
                        var price = data["price"];
                        alert(price);/// this works
                        return price;
                    }
                    else {
                        alert("Item could not be found.");
                        return;
                    }
                },
                error: function (req, status, errorObj) {
                    alert(errorObj.toString());
                }
            });
        }

}

if have this function it always returned "undefined" i tried testing it with alert()... the result was correct

why is my function always returned "undefined"?

  • You just asked the top JavaScript question: http://stackoverflow.com/questions/tagged/javascript?sort=frequent (at least at the time of writing this comment). – Felix Kling Jun 25 '15 at 01:40
  • Take a look at this: http://stackoverflow.com/questions/5316697/jquery-return-data-after-ajax-call-success#5316755 – DDan Jun 25 '15 at 01:40
  • you can try to add this JSON.parse(price); – Marcus Tan Jun 25 '15 at 01:58

0 Answers0