Ajax Lesson 4

 1.读取响应首部
    主要Code
   


function doHeadRequest(request,url,handle)
{
 alert("start head");
 requestType=request;
 createHttpRequest();
 xmlhttp.onreadystatechange=handle;
 xmlhttp.open("HEAD",url,true);
 xmlhttp.send(null);
 
}
function defaultHeadStateHandleFunction()
{
 if(xmlhttp.readystate==4)
 {
  if(requestType=="allResponseHeaders")
  {
   getAllResponseHeader();
  }else if(requestType=="lastModified")
  {
   getLastModified();
  }else if(requestType=="isResourceAvailable")
  {
   getIsResourceAvailable();
  }
  
 } 
}


function defaultHandleFunction()
{
 if(xmlhttp.readystate==4)
 if(xmlhttp.status ==200)
 {
   doResponsed(); //Need Define yourselef.
 } 
}



function getAllResponseHeader(){
 alert(xmlhttp.getAllResponseHeaders()); 
}


function getLastModified(){
 alert("Last Modified:"+xmlhttp.getResponseHeader("Last-Modified")); 
}
function getIsResourceAvailable()
{
 if(xmlhttp.status==200)
 {
  alert("Successful response");
 }else
  if(xmlhttp.status==404)
 {
  alert("Resource is Unavailable");
 }else  
 {
  alert("UnExpected Response status:"+xmlhttp.status);
 }
}


Read.html 内容


http://www.w3.org/TR/html4/loose.dtd">




Reading Response Headers


 

Reading Response Headers


  Read All Response headers
 

  Read Last Modify
 

  Read Available Resource
 

   Read Available Resource
 



注: 页面调用使用javascript:functionName ,javaScript 区分大小写.所以写的时候一定要注意.否则会出现对象无效错误.


 


2.动态刷新页面.


Dynai..html


http://www.w3.org/TR/html4/loose.dtd">



Ajax Dynamic Update




Ajax Dynamic Update Example


This page will automaticlly update itself:



 Page Will Refresh in 5 Seconds..






 
  
 


 


注.1.主要代码.SetTimeOut(function,timegap)可以固定timegap时间调用function执行.


2.需要服务器端响应.


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值