当前位置:编程学习 > JS >>

使用prototype.js经验积累

 

1、Ajax返回xml格式的对象

1)前台js

function viewIndexGrade(id){

       var offsetObj = event.srcElement;

       var url = "<ww:url value='/xxxAction!getIndexGrades.action'/>?obj.id=" + id;

       var http = new Ajax.Request(url,

              {method: 'get',

              asynchronous: false,

              onComplete:function(oriReq){

                     var divObj = document.getElementById("indexGradDiv");

                     var sb = "<table class='table-border' align='center' cellspacing='1' cellpadding='1' width='100%'>";

                     var responseDoc = oriReq.responseXML;

                     var records = responseDoc.documentElement.childNodes;

                     if(records.length > 0){

                            for(var i = 0; i < records.length; i++){

                                   var indexCode = records[i].selectSingleNode("indexCode").text;

                                   var grade = records[i].selectSingleNode("grade").text;

                                   sb += "<tr>";

                                   sb += "<td class='table-title' style='height:25px' align='left' width='40%'>" + indexCode + "</td>";

                                   sb += "<td class='table-content' style='height:25px' align='center'>" + grade + "</td>";

                                   sb += "</tr>";

                            }

                            sb += "</table>";

                            divObj.style.height = (25 * records.length + 10) + "px";

                     }else{

                            sb += "<tr>";

                            sb += "<td class='table-content' align='center'>无调查数据</td>";

                            sb += "</tr>";

                            sb += "</table>";

                            divObj.style.height = "40px";

                     }

                     divObj.innerHTML = sb;

                     while(offsetObj.tagName != "A"){

                            offsetObj = offsetObj.parentElement;

                     }

                     viewDiv(divObj, offsetObj, true, 0, 0);

              }

       });

}

</SCRIPT>

 

 

2)webwork配置

<xwork>

    <package name="XXX" extends="default">

              <action name="xxxAction" class="com.***.***.action.***Action">

 

                     <result name="xml" type="stringreader">

                            <param name="inputName">stringReader</param>

                            <param name="contentType">text/xml;charset=gb2312</param>

                            <param name="parse&

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,