给一个示例吧:
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=0i<versions.lengthi++) {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){www.hbbz08.com
obj.status=obj.r.status
obj.text=obj.r.responseText
obj.body=obj.r.responseBody
callpage()
}
}
}
把这个别存为Shopajax.js
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META Nwww.jdjdzj.comAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript" src="shopajax.jss"></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>
这个随便存一个页面保存为index.html
{"Money":2000.00,"Age":21}
把这个存成一个1.html
保存完后,点击Index.html就可以看到Div里面有值了。值是从1.html里面取到的。这个过程实现 了Ajax
<object>的功能是导入对象,一般的格式为:<object classid=...>
<param name=... value=...>
</object>
里面的<param>是用来指定对象的属性,至于对象有哪些属性,那就要看具体的对象了