簡體   English   中英

jQuery-Ajax-Struts2列表

[英]JQuery - Ajax - Struts2 list

我在獲取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){無法正確觸發,但看不到原因。

可能是“ lookupCustomerAjax”是無效的URL或文件名。 您應該嘗試添加擴展名。

另外,為進行故障排除,您應該連續繼承console.log(response)來查看實際得到的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM