I am new to jquery and I am trying to assign a value to a variable after an ajax call but it returns undefined. My code is below:
function prepareDocument() {
var a = getAverageRating(1);
alert(a);
}
function getAverageRating(pageId) {
$.ajax({
url: "../services/rating.ashx?action=getAverageRating&pageId=" + pageId,
dataType: "text",
type: "GET",
data: {},
error: function (err) {
displayDialogBox("Error", err.toString());
},
success: function (data) {
return data;
}
});
}
Any help would be appreciated. Thanks,