我正在尋找一些幫助,讓我的JQuery/Ajax調用從Struts動作返回List,並使用s:iterator填充列表元素的DIV。JQuery - Ajax - Struts2 list
我有以下的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>
而我的行動方法來迭代列表,因爲當我調試時,調試器會檢查代碼。
private List<Customer> customerList;
public String lookupCustomerAjax() {
dummyData();
return SUCCESS;
}
這successully叫我的行動方法,但我得到的是「讓我們開始」警報,那麼沒有別的,沒有錯誤,沒有什麼!
所以我猜這只是jQuery/Ajax的成功:function(response){不正確的火,但看不到爲什麼。
你能告訴。控制檯中顯示的錯誤是什麼。嘗試。螢火蟲/ IE開發人員/ Chrome。其中一個常見原因是jquery.js的放置不正確。還把你的函數放在$(document).ready(function(){}); –