I can't get the returned data of an GET AJAX call. The call gets the data properly but I can't get the data I need in a variable and return it.
I know that the AJAX calls are asynchronous and I've tried different approaches but failed.
   function getQuantity(Id) {
        var productQuantity = null;
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "/Product/ProductData/" + Id,
            success: function (response) {
                productQuantity = response.QuantityInStock;
                console.log("in call: ", productQuantity);
            }
        });
        console.log("in return: ", productQuantity);
        return productQuantity;
   }
This is what I get in the console:
in return: null
in call: 2724 -> this is the right value
Hope you can help.
 
    