I am getting a list from C# web method with ajax (code below), the list is returned fine, but after the success method is done, it gives me an error - (Cannot read property 'length' of undefined) in the jquery (screenshot below)
Am I missing something ??
function getMainParentMenus() {
    $.ajax({
        type: "POST",
        url: "/Mainpage.aspx/getLeftMainNavParentMenus",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert(msg.d);
            parentMenuss = msg.d;
        }, //It goes to the screenshot below after this bracket
        error: function (error) {
            alert("An error has occured while fetching the Left Nav Parent Menus");
        }
    });
};

The method above is called by the below method.
    var parentMenuss;
    var listOfSubMenus;
    function bindLeftNavMenu() {
//    var parentMenus = getMainParentMenus();
getMainParentMenus();
    var html = "<div id='accordian'> ddd";
    $.each(parentMenuss, function () {
        html += " <h3 class='accordianHeader' href='" + this['URL'] + "'>" + this['Title'] + "</h3>  ";
        alert("okK");
        $.each(listOfSubMenus, function () {
            html += "<div class='accordianContent'><a href='" + this['URL']  + "'>" + this['Title'] + "</a>";
        });
    });
    html += "</div>";
    $("#leftNavigationMenu").append(html);
 };
EDIT :
the data in the alert in the first block of code above is displayed like so 

and in the chrome debugger : 

 
     
     
    