ajax 局部刷新,返回json字符串

JSP:

$.ajax({

        target:"#myGiftTbody",
        type: "POST", 
        url: "queryGift.html",
        dataType: "json",
        success:function(data) {
            var tr;
            var td;
            var jsonObj = eval("("+data+")");
            if(jsonObj == null) {
                return error;
            }
            for (var i = 0; i < jsonObj.length; i++) {
                var mySecurityReportRecord = new Array();
                mySecurityReportRecord.push(jsonObj[i].name + "【兌換數:"+jsonObj[i].orderItemCount+"】");
                mySecurityReportRecord.push(jsonObj[i].createdDate);
                mySecurityReportRecord.push(jsonObj[i].receiverAddressDetail);
                mySecurityReportRecord.push(jsonObj[i].receiverName);
                mySecurityReportRecord.push(jsonObj[i].receiverMobile);
                 if ('COMMITED' == jsonObj[i].orderStatus) {
                     jsonObj[i].orderStatus = '已提交';
                 }else if ('CANCELED' == jsonObj[i].orderStatus) {
                     jsonObj[i].orderStatus = '已取消';
                 } else if ('CONFIRMED' == jsonObj[i].orderStatus) {
                     jsonObj[i].orderStatus = '已確認';
                 } else if ('SHIPMENT' == jsonObj[i].orderStatus) {
                     jsonObj[i].orderStatus = '發貨中';
                 } else if ('FINISHED' == jsonObj[i].orderStatus) {
                     jsonObj[i].orderStatus = '訂單完成';
                 }
                mySecurityReportRecord.push(jsonObj[i].orderStatus);
                mySecurityReportRecord.push(jsonObj[i].handleDescription);
                leakTableValues.push(mySecurityReportRecord);
            }
    
            for(var i=0;i<leakTableValues.length;i++) { 
                tr = document.createElement("tr");
                for(var j=0;j<leakTableValues[i].length;j++) { 
                    td = document.createElement("td");
                    td.innerHTML = "<span>"+ leakTableValues[i][j] + "</span>";
                    tr.appendChild(td);
                }
                document.getElementById("myGiftTbody").appendChild(tr);
                $("#test").val(1);
            }
        }

    });


JAVA:

將結果轉化爲json字符串:

JSONArray json = JSONArray.fromObject(list);
            this.setResult(json.toString());

ACTION配置:

<action name="announceQuery" class="com.huawei.src.action.view.CommonAction" method="forwardAnnouncement">
            <result type="json">
                <param name="root">result</param>
            </result>
        </action>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章