分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

ajax xml对象(比较少用,一般用json)

发布时间:2023-09-06 02:20责任编辑:苏小强关键词:jsjsonxml

<%@ page language="java" pageEncoding="utf-8" %><!DOCYPE Html><html> ???<head> ???????<meta http-equiv="content-type" content="text/html;charset=utf-8" /> ???????<title>ajaxXml!!!</title> ???????<script type="text/javascript"> ???????????function show(){ ???????????????//获得ajax对象 ????????????????var ajax; ???????????????if(window.XMLHttpRequest){ ???????????????????ajax=new XMLHttpRequest(); ???????????????}else if(window.AtiveXObject){ ???????????????????ajax=new AtiveXObject("Msxm12.XMLHTTP"); ???????????????} ???????????????//复写ajax.onreadystatechange ???????????????ajax.onreadystatechange=function(){ ???????????????????if(ajax.readyState==4){ ???????????????????????if(ajax.status==200){ ???????????????????????????//获得xml对象 ???????????????????????????var result=ajax.responseXML; ???????????????????????????alert(result.getElementsByTagName("name")[0].innerHTML); ???????????????????????} ???????????????????} ???????????????} ???????????????//请求发送到servlet ???????????????//ajax.open("get","ajaxXml"); ???????????????//请求发送到xml.jsp ???????????????ajax.open("get","xml.jsp"); ???????????????ajax.send(null); ???????????} ???????</script> ???????<style type="text/css"> ???????????#div{ ???????????????border:solid 2px; ???????????????width:200px; ???????????????height:100px; ???????????} ???????</style> ???</head> ???<body> ???????<div id="div"> ???????????<input type="button" value="show" onclick="show()" /> ???????</div> ???</body></html>
<%@ page language="java" contentType="text/xml; charset=utf-8" pageEncoding="utf-8" %><user> ???<uid>1</uid> ???<name>张三</name> ???<price>11.11</price></user>
public class AjaxXml extends HttpServlet{ ???@Override ???public void service(HttpServletRequest request,HttpServletResponse response) throws IOException { ???????request.setCharacterEncoding("utf-8"); ???????response.setCharacterEncoding("utf-8"); ???????response.setContentType("text/XML;charset=utf-8"); ???????response.getWriter().write("<user><uid>1</uid><name>张三</name><price>11.11</price></user>"); ???????System.out.println("test"); ???}}
public class AjaxXml extends HttpServlet{ ???@Override ???public void service(HttpServletRequest request,HttpServletResponse response) throws IOException { ???????request.setCharacterEncoding("utf-8"); ???????response.setCharacterEncoding("utf-8"); ???????response.setContentType("text/XML;charset=utf-8"); ???????response.getWriter().write("<user><uid>1</uid><name>张三</name><price>11.11</price></user>"); ???????System.out.println("test"); ???}}

ajax xml对象(比较少用,一般用json)

原文地址:https://www.cnblogs.com/lastingjava/p/9898647.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved