Struts2 Div Ajax 重新加载

发布于 2024-11-28 15:36:00 字数 757 浏览 0 评论 0原文

我有一个简单的用例,

    <div id="contentDiv">

            <!-- This does not work -->
            <div id="frmDiv">
                    <s:form action="..">
                            <s:a target="contentDiv" theme="ajax">Reload</s:a>
                    </s:form>
            </div>

            <!--This works -->
            <div id="listDiv">
                    <s:a target="frmDiv" theme="ajax" someaction >Click Me</s:a>
            </div>
    </div>

我注意到当链接的目标位于同一目标内时,此 ajax 操作不起作用。当链接目标位于 div 之外时,这将按要求工作。

重新加载相同 div 或将其设置为 ajax 结果目标的任何解决方法。

我正在使用 struts 2.0.14

Also here 而不是链接,如果我使用按钮,这不起作用。任何解决方法将不胜感激。

I have a simple use case

    <div id="contentDiv">

            <!-- This does not work -->
            <div id="frmDiv">
                    <s:form action="..">
                            <s:a target="contentDiv" theme="ajax">Reload</s:a>
                    </s:form>
            </div>

            <!--This works -->
            <div id="listDiv">
                    <s:a target="frmDiv" theme="ajax" someaction >Click Me</s:a>
            </div>
    </div>

I have noticed when a target of a link which is within the same target then this ajax action does not work. While when target of link is outside the div this works as required.

Any workaround to reload same div or set it as target for ajax result.

I am using struts 2.0.14

Also here instead of link if I use button this does not work. Any work-around will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最初的梦 2024-12-05 15:36:00

当有意义的时候才使用 html。从长远来看,使用没有标签库的 ajax 可能是更快的方法。它们非常适合模板和简单的逻辑,但随着客户端需求变得更加苛刻,它们很快就会失败。

您应该升级应用程序,任何东西都不太可能损坏,并且您会获得一些新功能。您遇到的问题可能并不存在。尚未对其进行测试,但自该版本以来,标签库已进行了许多改进和修复。

<a href="#first">link to first</a>
<a href="#second">link to second</a>

<!-- following weird ognl was used because you are at version 2.0.14, you should upgrade then I could have used the begin and end attributes, like in c:forEach-->
<s:iterator value="(84).{ #this }" >
  <br/>
</s:iterator>

<div id="first">
 This is first.
</div>

<s:iterator value="(84).{ #this }" >
  <br/>
</s:iterator>

<div id="second">
 This is second
</div>

Just use html when it makes sense. Also using ajax witout tag libraries is probably the faster way in the long run. They are great for templates and simple logic but as client side needs become more demanding they quickly fail.

You should upgrade the application, it is highly unlikely anything would break and you get some new features. It's possible the issue you are experiencing does not exist. Have not tested it but the tag library has had a number of improvements and fixes since that version.

<a href="#first">link to first</a>
<a href="#second">link to second</a>

<!-- following weird ognl was used because you are at version 2.0.14, you should upgrade then I could have used the begin and end attributes, like in c:forEach-->
<s:iterator value="(84).{ #this }" >
  <br/>
</s:iterator>

<div id="first">
 This is first.
</div>

<s:iterator value="(84).{ #this }" >
  <br/>
</s:iterator>

<div id="second">
 This is second
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文