This article mainly introduces how JS uses ajax to obtain the specified field value in the header information of a specified url. The example analyzes the head information in the Ajax operation URL and has some reference value, for more information about how to use ajax to obtain the value of a specified field in the header of a specified url, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
The following js code is used to obtain the Last modified attribute in the head Information of ajax_info.txt, and the Last modification time.
《script》function loadXMLDoc(url){var xmlhttp;if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById('p1').innerHTML="Last modified: " + xmlhttp.getResponseHeader('Last-Modified'); } }xmlhttp.open("GET",url,true);xmlhttp.send();}《script》The getResponseHeader() function is used to return specific header information from a resource, like length, server-type, content-type, last-modified, etc.
Get "Last-Modified" information
I hope this article will help you design javascript programs.