Ajax返回xml类型数据
来源:互联网 发布:js防水涂料粘接强度 编辑:程序博客网 时间:2024/06/05 00:56
1
2
ajax可以返回文本类型数据和xml类型数据,xml是计算机通用语言
可以使用js解析返回xml类型数据的dom对象
前端页面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!
doctype
html>
<
html
lang="en">
<
head
>
<
meta
charset="UTF-8">
<
meta
name="Generator" content="EditPlus®">
<
meta
name="Author" content="">
<
meta
name="Keywords" content="">
<
meta
name="Description" content="">
<
title
>Ajax</
title
>
<
script
type="text/javascript">
function createXHR(){
var xhr=null;
if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}else if(window.ActiveXObject){
xhr=new ActiveXObject('Microsoft.XMLHttp');
}
return xhr;
}
function returnxml(){
var xhr=createXHR();
xhr.open('GET','./returnxml.php',true);
xhr.onreadystatechange=function (){
if(this.readyState==4&&this.status==200){
//alert(this.responseXML);//[object XMLDocument]
var xmldom=this.responseXML;
var title=xmldom.getElementsByTagName('title')[0];
var title=title.firstChild.wholeText;
var str='书名:'+title+'<
br
/>';
var price=xmldom.getElementsByTagName('price')[0].firstChild.wholeText;
var desc=xmldom.getElementsByTagName('desc')[0].firstChild.wholeText;
str=str+'价格:'+price+'<
br
/>';
str=str+'详细信息:'+desc+'<
br
/>';
str=str+'状态码:'+this.status+'<
br
/>';
str=str+'状态文字:'+this.statusText+'<
br
/>';
str=str+'返回值类型:'+this.getResponseHeader('content-type')+'<
br
/>';
str=str+'返回值长度:'+this.getResponseHeader('content-length')+'<
br
/>';
str=str+'ip:'+this.getResponseHeader('x-forwarded-for')+'<
br
/>';
document.getElementById('book').innerHTML=str;
}
}
xhr.send(null);
}
</
script
>
</
head
>
<
body
>
<
input
type="button" value="返回值xml" onclick="returnxml();"/>
<
div
id="book"></
div
>
</
body
>
</
html
>
returnxml.php
1
2
3
4
5
<?php
header(
'content-type:text/xml'
);
?>
<?xml version=
"1.0"
encoding=
"utf8"
?>
<bookstore><book><title>ajax详解</title><price>39.9元</price><desc>学习ajax的最强帮</desc></book></bookstore>
结果显示效果
阅读全文
0 0
- Ajax返回xml类型数据
- Ajax返回XML数据
- AJAX第二步:AJAX接收返回类型为text/XML的数据
- Ajax servlet 返回xml数据乱码问题
- ajax请求Struts2返回xml数据方法
- ajax处理返回的xml格式数据
- 学习笔记--Ajax:XML格式返回数据
- Servlet如何返回XML类型的数据
- ajax 接收json,xml类型数据
- Struts2+Jquery实现ajax并返回json类型数据
- Struts2+Jquery实现ajax并返回json类型数据
- Struts2+Jquery实现ajax并返回json类型数据
- Struts2+Jquery实现ajax并返回json类型数据(MARK)
- Struts2+Jquery实现ajax并返回json类型数据
- Struts2+Jquery实现ajax并返回json类型数据
- Struts2+Jquery实现ajax并返回json类型数据
- 关于 Ajax中返回json类型数据为什么使用? eval()
- Struts2+Jquery实现ajax并返回json类型数据
- c++ 采集nvidia GPU使用率
- 批量重命名
- 杂七杂八
- Ubuntu下无法手动启动VMware Tools安装
- Ubuntu 蓝屏拯救
- Ajax返回xml类型数据
- 词向量源码解析:(6.1)fasttext源码解析
- 数据库-事务
- 代理模式
- LeetCode678. Valid Parenthesis String
- leetcode
- mongodb用户权限管理配置
- 使用jquery处理ajax返回的XML、无刷新技术
- Redis之五种数据类型