zoukankan
html css js c++ java
ajax的一个最简单例子
{"Money":2000.00,"Age":21}
main.htm
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
HTML
>
<
HEAD
>
<
TITLE
>
New Document
</
TITLE
>
<
META
NAME
="Generator"
CONTENT
="EditPlus"
>
<
META
NAME
="Author"
CONTENT
=""
>
<
META
NAME
="Keywords"
CONTENT
=""
>
<
META
NAME
="Description"
CONTENT
=""
>
<
script
type
="text/javascript"
src
="shopajax.js"
></
script
>
</
HEAD
>
<
BODY
>
<
div
id
="as"
></
div
>
<
SCRIPT
LANGUAGE
="JavaScript"
>
<!--
var
ajax
=
new
xmlhttp();
debugger
ajax.getopen(
"
1.html
"
);
function
callpage()
{
if
(ajax.status
==
0
)
{
//
本地为0,远程为200
var
obj
=
eval('('
+
ajax.text
+
')');
document.getElementById(
"
as
"
).innerHTML
=
"
年纪:
"
+
obj.Age
+
"
<br>薪水:
"
+
obj.Money;
}
}
//
-->
</
SCRIPT
>
</
BODY
>
</
HTML
>
shopajax.js:
function
requestHttp()
{
var
request;
if
(window.XMLHttpRequest)
{
request
=
new
XMLHttpRequest();
if
(request.overrideMimeType)
{request.overrideMimeType('text
/
xml');
}
}
else
if
(window.ActiveXObject)
{
var
versions
=
['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.
7.0
', 'Msxml2.XMLHTTP.
6.0
', 'Msxml2.XMLHTTP.
5.0
', 'Msxml2.XMLHTTP.
4.0
', 'MSXML2.XMLHTTP.
3.0
', 'MSXML2.XMLHTTP'];
for
(
var
i
=
0
; i
<
versions.length; i
++
)
{
try
{request
=
new
ActiveXObject(versions[i]);
break
;}
catch
(e)
{}
}
}
return
request;
}
function
xmlhttp()
{
this
.r
=
requestHttp();
}
xmlhttp.prototype.postopen
=
function
(url,data)
{
this
.r.open('POST',url,
false
);
this
.r.setrequestheader(
"
content-type
"
,
"
application/x-www-form-urlencoded
"
);
this
.r.onreadystatechange
=
ReadyStateChange(
this
);
if
(
typeof
(data)
==
'undefined')
this
.r.send();
else
this
.r.send(data);
}
xmlhttp.prototype.getopen
=
function
(url)
{
if
(window.XMLHttpRequest)
{
this
.r.open('GET',url);
this
.r.onreadystatechange
=
ReadyStateChange(
this
);
this
.r.send(
null
);
}
else
{
this
.r.open(
"
GET
"
, url,
true
);
this
.r.onreadystatechange
=
ReadyStateChange(
this
);
this
.r.send();
}
}
ReadyStateChange
=
function
(obj)
{
return
function
()
{
if
(obj.r.readyState
==
4
)
{
obj.status
=
obj.r.status;
obj.text
=
obj.r.responseText;
obj.body
=
obj.r.responseBody;
callpage();
}
}
}
1.html:
查看全文
相关阅读:
关于struts2的checkboxlist、select等标签发生could not be resolved as a collection/array/map/enumeration/iterator type异常的记录
ajax Session失效如何跳转到登录页面
将默认首页设置成index.do的方法
tomcat应用转到weblogic上时的问题
MyEclipse 8.5整合Git,并在Github上发布项目(转)
C++ 类设计核查表
编程书籍
并发模型
C++ AOP手法
编程 网上资源平台
原文地址:https://www.cnblogs.com/cutepig/p/937429.html
最新文章
避免SQL全表模糊查询查询
sql servse 查询当前库内表索引值
sql server 生成数据库字典 sql语句
如何 DataTable格式转换json格式
杨辉三角形
.net core EFcore model生成数据
.net 配置swagger
UML(6)UML表示类之间的关系-关联关系其他/三角还没没有总结完成
UML(5)UML表示类之间的关系-关联关系/三角还没没有总结完成
UML(4)UML类图/三角还没没有总结完成
热门文章
UML(3)UML结构其他/三角还没没有总结完成
UML(2)UML结构/三角还没没有总结完成
UML(1)UML特性/三角还没没有总结完成
进一步学习设计模式(10)多学设计模式/三角还没没有总结完成
进一步学习设计模式(9)敲代码,多运用设计模式/三角还没没有总结完成
进一步学习设计模式(8)学习设计模式的建议/三角还没没有总结完成
进一步学习设计模式(7)设计模式有什么用/三角还没没有总结完成
java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist
struts2 taglib struts标签学习整理中
javascript收集整理
Copyright © 2011-2022 走看看