【发布时间】:2012-06-15 00:56:40
【问题描述】:
我正在寻求一些帮助,让我的 JQuery/Ajax 调用从 Struts 操作返回一个列表,并使用 s:iterator 用列表元素填充一个 DIV。
我有以下 JQuery
function lookupCustomerJs() {
alert("lets start");
$.ajax({
type: "POST",
url: "lookupCustomerAjax",
data: $('#lookupCustomer').serialize(),
success:function(response) {
alert("do stuff");
$('div#custList').replaceWith($(response).find("div#custList"));
},
failure:function(response) {
alert('Ajax call failed');
},
error:function(response) {
alert(exception);
}
});
}
我的页面中有一个 DIV,然后我想遍历列表
<div id="custList">
<s:iterator status="stat" value="customerList" var="customer">
<s:param name="custFName" value="%{customer.firstname}" />
</s:iterator>
</div>
还有我调用的 Action 方法,因为当我调试时,调试器会遍历代码。
private List<Customer> customerList;
public String lookupCustomerAjax() {
dummyData();
return SUCCESS;
}
这成功调用了我的 Action 方法,但我得到的只是“让我们开始”警报,然后什么都没有,没有错误,什么都没有!
所以我猜这只是 jQuery/Ajax 成功:function(response) { 没有正确触发,但看不出原因。
【问题讨论】:
-
你能告诉我吗?控制台中究竟显示了什么错误。尝试 。 firebug/IE 开发者/Chrome 。一般原因之一是 jquery.js 的位置不正确。也把你的功能 $(document).ready(function() { });