我在通过Struts 2中的Ajax调用加载内容时遇到了一个简单的问题(使用Struts2 Dojo插件)。它正在从页面正确加载所有HTML内容,但如果该页面内有任何内联JavaScript函数,则不会加载所有内容。我不知道struts Ajax是否有一些限制。
这是我的parent.jsp
:
<s:head/>
<body>
<div id="casetab2" class="casetab_content">
<sx:div href="LoadContent" delay="3000">
Initial Content
</sx:div>
</div>
</body>
这是我的child.jsp
:
<s:text name="name" label="NAME"/>
<script>alert("hello")</script>
这是我的struts.xml
:
<action name="LoadContent">
<result>child.jsp</result>
</action>
结果:显示NAME:<textfield>
但未显示提示消息。
答案 0 :(得分:2)
这是一个众所周知的问题......
理论上,只需将executeScripts="true"
添加到<sx:div/>
即可,但如果还不够,请尝试使用separateScripts
属性。
答案 1 :(得分:1)
警报消息未提交,因为它未编译为有效的javascript。如果你打开萤火虫,你会发现错误很重要。使用以分号版本代码更正
<script type="text/JavaScript">alert("hello");</script>
其他错误修复:
1)包含head代码
2)根据Andrea的回答,使用tag attributes
<head>
<sx:head/>
</head>
<body>
<div id="casetab2" class="casetab_content">
<sx:div href="LoadContent" delay="3000" separateScripts="false" executeScripts="true">
Initial Content
</sx:div>
</div>
</body>