Ajax源代码

Ajax源代码
Ajax源代码

Ajax源代码

代码清单2-1,创建XMLHttpRequest对象

#001

代码清单2-2,将JavaScript嵌入html页面中

#001 …….

#002

#003

#004

#009

#010

#011

#012

#013 ……

代码清单2-3 标签应用示意

#001

代码清单2-5 使用getAllResponseHeaders()得到HTTP响应全部信息

#001 var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");

#002 xmlhttp.open("GET", "http://localhost/sample.xml", false);

#003 xmlhttp.send();

#004 document.write(xmlhttp.getAllResponseHeaders());

代码清单2-6 GET方式提交的HTTP头内容:``

#001 GET /ajaxstudy/function.jsp? reqparam = reqparamvalue HTTP/1.1

#002 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*

#003 Referer: http://localhost//example.html

#004 Accept-Language: zh-cn

#005 Accept-Encoding: gzip, deflate

#006 User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)

#007 Host: localhost:8080

#008 Connection: Keep-Alive

代码清单2-7 向服务器发送GET请求

#001

#002

#003

#004

代码清单2-8 POST方式提交的HTTP头内容

#001 POST /ajaxstudy/function.jsp HTTP/1.1

#002 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-

#003 powerpoint, application/vnd.ms-excel, application/msword, */*

#004 Referer: http://localhost//other.html

#005 Accept-Language: zh-cn

#006 Content-Type: application/x-www-form-urlencoded

#007 Accept-Encoding: gzip, deflate

#008 User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)

#009 Host: localhost:8080

#010 Content-Length: 9

#011 Connection: Keep-Alive

#012 reqparam=reqparamvalue

代码清单2-9 使用POST方式提交请求

#001

#002

#003

#004

代码清单2-10 同时提交GET与POST请求

#001

#002

#003

#004

相关主题
相关文档
最新文档