So this is my controller action, it gets a double (average) from a service and returns it as a JSON
Controller name(Product)
[HttpGet]
public JsonResult getAvgRating(int productId)
{
double average = new WCF_Ratings.WCF_RatingsClient().getAvgRating(productId);
return Json(average, JsonRequestBehavior.AllowGet);
}
This is the jquery function which gets the data, the data is shown correctly in the alert
function getAvg()
{
$.getJSON("/Product/getAvgRating", { "productId": productId }, function (data) {
alert(data);
return data;
});
}
When I try to read the data from outside the jquery function by calling the function getAvg() I get unidentified data in my alert window.
$("#testbutton").click(function ()
{
var d = getAvg();
alert(d);
});
Can someone tell me why this is happening?