Struts2 jsp page opening in a new window instead of content div

Aniket V

I have a Struts2 application in which the home page is horizontally split into Header, Menu, Content and Footer. On click of the menu, a "navigate" action is invoked via JQuery and Ajax. The menu name is passed as a parameter to the action through the s:url tag. Based on the menu name, the JSP page name is dynamically prepared. However the Ajax response does not get loaded in the Content part of the page but gets redirected to a new page. I am not sure why this is happening. Below are the code snippets.

Menu.jsp

<!-- Dynamic Menu Bar -->
<div id="menu" class="divMenu">
    <ul>
        <s:iterator var="parent" value="menuList">
            <li>
                <s:a href="#">
                    <s:property value="#parent.menuDesc" />
                </s:a>
                <ul class="sub-menu">
                    <s:iterator var="child" value="#parent.childrenList">
                        <li>
                            <s:url var="urlValue" action="navigate">
                                <s:param name="pageName" value="#child.menuDesc" />
                            </s:url>
                            <s:a method="post" href="%{urlValue}" onclick="menuNavigate(this)">
                                <s:property value="#child.menuDesc" />
                            </s:a>
                        </li>
                    </s:iterator>
                </ul>
            </li>
        </s:iterator>
    </ul>
</div>

JavaScript Function

function menuNavigate(action) {
    alert(action);
    $.ajax({
        type : "POST",
        url : action + ".action",
        datatype: "html",
        success : function(response) {
            alert(response);
            $("#content").html(response);
        },
        error : function(err) {
            $("#content").html(err);
        }
    });
}

BTW, I am able to see the response using the alert under the success part of the Ajax call. On clicking OK, the response gets displayed in a new window.

Struts2 XML

<action name="navigate" class="com.web.action.home.HomePageAction" method="navigate">
    <result name="success">/WEB-INF/pages/${pageName}</result>
</action>
Aniket V

Adding an event.preventDefault() worked for me. Thanks for all of them who provided their valuable suggestions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to pass the values to new window using jsp in struts2

From Dev

Include css in struts2 jsp page

From Dev

page not opening inside iframe content window

From Dev

opening a new window based on the current url of the page

From Dev

opening a new window based on the current url of the page

From Dev

why is window.open(url) opening new window instead of tab

From Dev

Loaded div accordion opening in window instead of container div

From Dev

Setting the action text in JSP page in Struts2

From Dev

Join two Map on Jsp page - Struts2 application

From Dev

How to include css files in JSP page struts2?

From Dev

Struts2 - returning to a specific section and/or part of a .jsp page

From Dev

How to include css files in JSP page struts2?

From Dev

How to generate PDF in new window using itext in Struts2

From Dev

How to generate PDF in new window using itext in Struts2

From Dev

Force button to reload page after opening new window

From Dev

object contents lost when opening new page within window

From Dev

page opening in both window

From Dev

Window not opening in a new tab

From Dev

opening a link in a new window

From Dev

Opening new window in wicket

From Dev

Opening New Window in Jframe

From Dev

New Page getting open inside tabs view instead of opening as new page

From Dev

Copying content of a div to a new window adds extra unwanted new line

From Dev

Edge and opening a new page

From Dev

Append content to new browser window from the parent page

From Dev

page is opening on browser instead of Webview

From Dev

opening window and navigating through page

From Dev

Opening a new terminal window in C

From Dev

Opening new window from ViewModel

Related Related

HotTag

Archive