Ajax是从bodyTile div标签中删除元素但不显示另一个元素(页面)

时间:2016-02-11 07:20:17

标签: ajax struts2

这是我的menubar.jsp页面。它包含一些链接,当我执行某些操作时,它正在删除正文块Div标签元素但不显示另一个页面

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<link rel="stylesheet" type="text/css"
href="<c:url value="/resources/css/SpryMenuBarHorizontal.css"/>">
<script src="<c:url value="/resources/js/SpryMenuBar.js"/>"></script>
<script type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js'>    
</script>
<script type="text/javascript">
function editr(val) {
    alert("hi" + val);
    $('#bodyTile').children().remove();
    $('#bodyTile').load(val);

}
</script>
</head>
<body>
<div id="menuTile">
<ul id="MenuBar1" class="MenuBarHorizontal">
<li><a href="#">Colleges</a></li>
        <li><a class="MenuBarItemSubmenu" href="#">Syllabus</a>
            <ul>
                <s:iterator value="#session.course">
                    <li><a class="MenuBarItemSubmenu" href="#">   
<s:property
                                value="courseName" /></a>
                        <ul>
                            <s:iterator value="semisters">
            <li><s:url action="UrlTag1Link.action"  var="urlTag1"
                                        escapeAmp="false">
                                        <s:param name="semisterId">
                                            <s:property      
value="semisterId" />
                                        </s:param>
                                        <s:param name="courseId">
                                            <s:property 
value="courseId"   />
                                        </s:param>
                                    </s:url><a href="<s:property 
value="#urlTag1" />"> <s:property
                                            value="semisterName" /></a>
                                    <ul>
                                        <s:iterator value="subjects">
                                            <li><s:url 
action="urlTagLink.action" var="urlTag"
                                                    escapeAmp="false">
                                                    <s:param 
name="semisterId">
                                                        <s:property 
value="semisterId" />
                                                    </s:param>
                                                    <s:param 
name="courseId">
                                                        <s:property 
value="courseId" />
                                                    </s:param>
                                                    <s:param 
name="subjectId">
                                                        <s:property 
value="subjectId" />
                                                    </s:param>
                                                </s:url> <a

href="javascript:editr('<s:property value="#urlTag" />')"><s:property

value="subjectName" /></a></li>
                                        </s:iterator>
                                    </ul></li>
                            </s:iterator>
                        </ul></li>
                </s:iterator>
            </ul>
        <li><a href="#">About Us</a></li>
        <li><a href="#">Contact Us</a></li>
        <li><a href="<s:url action="logout"/>">Logout</a></li>
    </ul>
</div>
<script src="<c:url value="/resources/js/jquery-2.0.3.min.js"
/>"></script>
<script type="text/javascript">
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {
        imgDown : "SpryAssets/SpryMenuBarDownHover.gif",
        imgRight : "SpryAssets/SpryMenuBarRightHover.gif"
    });
</script>

</body>

</html>

这是我的Tile.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
   "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
   "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>

<definition name="welcome" template="/mau.jsp">
    <put-attribute name="myHeader" value="/header.jsp" />
    <put-attribute name="myMenubar" value="/menubar2.jsp" />
    <put-attribute name="myRight" value="/right.jsp" />
    <put-attribute name="myLeft" value="/left.jsp" />
    <put-attribute name="myBody" value="/body.jsp" />
    <put-attribute name="myFooter" value="/footer.jsp" />
</definition>

<definition name="page1" extends="welcome">
     <put-attribute name="myBody" value="/page1.jsp" />
</definition>
 <definition name="page2" extends="welcome">
    <put-attribute name="myBody" value="/page2.jsp" />
  </definition>
</tiles-definitions>

这是baseLayout jsp页面(mau.jsp)

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>
<div style="width: 1000px height:600px;">
      <table style="width: 100%;">
        <tr>
            <td colspan="3" style="height: 100px; background-color: 
yellow;">
                <div id="headerTile">
                    <tiles:insertAttribute name="myHeader" flush="false" 
/>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <div id="menuTile">
                    <tiles:insertAttribute name="myMenubar" 
flush="false" />
                </div>
            </td>
        </tr>
        <tr>
            <td height="60%" width="25%">
                <div id="leftTile"
                    style="width: 100%; height: 400px; background-color: 
green;">
                    <tiles:insertAttribute name="myLeft" flush="false" />
                </div>
            </td>
            <td>
                <div id="bodyTile" style="width: 100%; height: 400px;">
                    <tiles:insertAttribute name="myBody" flush="false" />
                </div>
            </td>
            <td height="60%" width="25%">
                <div id="rightTile"
                    style="width: 100%; height: 400px; background-color: 
red;">
                    <tiles:insertAttribute name="myRight" flush="false" 
/>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <div id="footerTile">
                    <tiles:insertAttribute name="myFooter" flush="false" 
 />
                   </div>
              </td>
        </tr>
</table>
</div>
</body>
</html>

这是Struts.xml中定义的操作

    <action name="urlTagLink" 
  class="org.srtmun.student.action.UrlTagLinkAction"
          method="subjectName">
          <result name="page1" type="tiles" >page1</result>
    </action>
    <action name="UrlTag1Link"  
  class="org.srtmun.student.action.UrlTag1LinkAction"
        method="semisterName">
        <result name="page2" type="tiles">page2</result>
      </action>

1 个答案:

答案 0 :(得分:1)

我认为这个问题在第一行完全完成之前执行了第二行。 尝试使用settimeout函数或在/ jquery中使用/ then或deffered-Promise功能。