I have this JS ajax GET that returns menus to be used in a view. I wanted to see if there is any more way to write this method. Its a lot of code and just wanted to make sure there is no better way to do this?
console.log('Processing Login ajax GetMenuLinkList')
var url = "/login/GetMenuLinkList";
$.ajax({
type: "GET",
data: param = "",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: url,
success: function (data, status) {
console.log(data);
$('#favoritepagesListBlock').empty();
$('#meetingsanddisclosuresBlock').empty();
$('#memberinstitutionBlock').empty();
$('#orderListBlock').empty();
var orderShowMore = false;
var subscriptionShowMore = false;
$.each(data, function (index, data) {
switch (data.PageSection) {
case 1:
$('#favoritepagesListBlock').append("<a class='link-text' href='"+data.Url+"'>" + data.PageName + "</a>");
break;
case 2:
$('#meetingsanddisclosuresBlock').append("<a class='link-text' href='" + data.Url + "'>" + data.PageName + "</a>");
break;
case 3:
$('#memberinstitutionBlock').append("<a class='link-text' href='" + data.Url + "'><b>" + data.PageName + "</b></a>");
break;
case 4:
$('#orderListBlock').append("<a class='link-text' href='" + data.Url + "'>" + data.PageName + "</a>");
orderShowMore = data.ShowMore;
break;
case 5:
$('#subscriptionListBlock').append("<a class='link-text' href='" + data.Url + "'>" + data.PageName + "</a>");
subscriptionShowMore = data.ShowMore;
break;
}
});
if (orderShowMore = true) {
$('#orderListBlock').append("<a class='show-more' href='/home/store/order-history'>View More</a>");
}
if (subscriptionShowMore=true) {
$('#subscriptionListBlock').append("<a class='show-more' href='/home/store/subscriptions'>View More</a>");
}
},
error: function (request, status, error) {
// alert(request.responseText);
}
});