如何解决如何将Ajax响应列表用作struts2迭代器值?
Main.jsp(完整)
<%@ taglib prefix="s" uri="struts-tags.tld" %>
<html>
<head>
<script>
$(function(){
$('#loader').on("keypress click", function(e) {
$.ajax({
url: "<s:url action='ajaxAction'/>",
}).done(function(result) {
$("#target").html(result);
});
});
});
</script>
</head>
<body>
<input type="button" id="loader" />
<div id="target"></div>
<body>
</html>
Struts.xml(相关)
<action name="ajaxAction" class="foo.bar.AjaxAction">
<result>Snippet.jsp</result>
</action>
AjaxAction(相关)
private String testString;
/* Getter and Setter */
public String execute(){
testString = "I'm loaded with AJAX";
return SUCCESS;
}
Snippet.jsp(完整)
<%@ taglib prefix="s" uri="struts-tags.tld" %>
<!-- This is the result page. You can use Struts tags here,
the generated HTML will be appended to the target div. -->
TestString: <s:property value="testString" />
输出:
<body>
<input type="button" id="loader" />
<div id="target">TestString: I'm loaded with AJAX</div>
<body>
解决方法
我正在使用以下ajax函数:
$.ajax({
url: "userhomeonload",contentType: 'application/json',type: 'POST',datatype:'json',async: true,success: function (res) {
alert(res[i].name+" "+res[i].rollNo);
} });
我在警告框中得到正确的结果。现在,我想在struts迭代器中使用此ajax返回的列表,如下所示:
<s:iterator value="list">
<div>
<s:property value='name'></s:property>
<s:property value="rollNo"></s:property>
</div>
</s:iterator>
但是屏幕上没有任何显示。谁能告诉我该怎么做?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。