首页 > 开发 > AJAX > 正文

JS使用ajax方法获取指定url的head信息中指定字段值的方法

2024-09-01 08:33:28
字体:大 中 小
来源:转载
供稿:网友

这篇文章主要介绍了JS使用ajax方法获取指定url的head信息中指定字段值的方法,实例分析了Ajax操作URL中head信息的技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了JS使用ajax方法获取指定url的head信息中指定字段值的方法。分享给大家供大家参考。具体分析如下:

下面的JS代码用来获取ajax_info.txt的head信息中的Last modified属性,最后修改时间

 

 
  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4. <script> 
  5. function loadXMLDoc(url) 
  6. { 
  7. var xmlhttp; 
  8. if (window.XMLHttpRequest) 
  9. {// code for IE7+, Firefox, Chrome, Opera, Safari 
  10. xmlhttp=new XMLHttpRequest(); 
  11. } 
  12. else 
  13. {// code for IE6, IE5 
  14. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
  15. } 
  16. xmlhttp.onreadystatechange=function() 
  17. { 
  18. if (xmlhttp.readyState==4 && xmlhttp.status==200) 
  19. { 
  20. document.getElementById('p1').innerHTML="Last modified: " + xmlhttp.getResponseHeader('Last-Modified'); 
  21. } 
  22. } 
  23. xmlhttp.open("GET",url,true); 
  24. xmlhttp.send(); 
  25. } 
  26. </script> 
  27. </head> 
  28. <body> 
  29. <p id="p1">The getResponseHeader() function is used to return specific header information from a resource, like length, server-type, content-type, last-modified, etc.</p> 
  30. <button onclick="loadXMLDoc('ajax_info.txt')">Get "Last-Modified" information</button> 
  31. </body> 
  32. </html> 

希望本文所述对大家的javascript程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表