xml携带数据更多,更加普遍。
服务器返回xml格式的数据:
response.addheader("Content-Type","text/xml;charset=utf-8"); response.addheader("Cache-Control","no-cache"); PrintWriter out = response.getWriter(); String username=request.getParameter("username"); String res="<res><mes>"+username+"</mes></res>"; out.print(res); out.flush(); out.close();
ajax如何处理返回数据格式是xml的?
if(myXmlHttpRequest.readyState==4){ //若是返回一个文本 ,则使用responseText 若是返回一个XML,则使用responseXML //window.alert("服务器返回值:"+myXmlHttpRequest.responseText); //如何取出xml的数据 var mess=myXmlHttpRequest.responseXML.getElementsByTagName("mes"); window.alert(mess); var msg=mess[0].childNodes[0].nodeValue;//mess[0] 表示<mes>username</mes> 它的第一个子节点即文本节点,文本节点的nodeValue即文本值。 window.alert(msg); }主要思想就是通过DOM编程,解析xml
原文地址:https://www.jb51.cc/ajax/161399.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。