Search code examples
javascriptjqueryhtmlajaxjava-ee-7

Data on site not showing after clicking on sub menu on nested unordered list using ajax with jquery


Here is the html unordered list implementation

<div id="dropdownmenu" style="position: fixed; margin: 0 auto; width: 100%; position: fixed; opacity: 1; text-align: center;">
        <ul id='navbar' class="menu">
            <li><a href="Home">Home</a></li>
            <li class="active"><a href="#s2"><%= session.getAttribute("name") %></a>
            <ul id='profile' class="submenu">
            <li id='account'>Account</li>
            <li id='password'><a>Change Password</a></li>
            <li id='myitinerary'><a>My Itineraries</a></li>
            <li id='promotions'><a>Promotions</a></li>
            </ul>
            </li>
            <li><a href="/ExpressBus-war/Logout">Logout</a></li>
        </ul>
        </div>

and here is the script i am trying to run

<script>         
            $(function() {
                $("#dropdownmenu").click(function(event) {
                    if(event.target.id === 'myitinerary')
                    {
                        $.post({
                            type: 'POST',
                            data: {
                                username: <%= session.getAttribute("username") %>;
                            },
                            url: "GetItineraries",
                            success: function(result){
                                $('#content2').empty();
                                $("#content3").empty();
                                $("#content4").empty();
                                $('#content').html(result);
                            }
                        });
                    }
                });
            });
        </script>

I am using Netbeans EE, basically what i intend to do is to fill the content with the result i obtained from the servlet. But so far everything i have tried isnt working out.


Solution

  • I managed to solve the problem, i needed to modify a few things on my script. And it worked later.

    $(function() {  
                    $("#profile li").click(function(event) {
                        if(event.target.id === 'myitinerary')
                        {
                            $.post({
                                type: 'POST',
                                data: {username: '<%= session.getAttribute("name") %>' },
                                url: "GetItineraries",
                                success: function(result){
                                    $('#content2').empty();
                                    $("#content3").empty();
                                    $("#content4").empty();
                                    $('#content').html(result);
                                }
                            });
                        }
                    });
                });