how to get header information of a website???
var req = new XMLHttpRequest();
req.open('GET', 'http://localhost/gp/index.php', false);
req.send(null);
if(req.status == 200) {
alert(req.getResponseHeader('Content-type'));
alert(req.getAllResponseHeaders());
this code is working fine and giving the HEADER information;but if i change the URL and put http://www.google.com, then it is not working.........plzzzz i need help.
RE: how to get header information of a website???
Here is the code i tried with. It is running with other url but not with google. There may be some security risk for which you are not getting the result you want.
<script>
function xmlhttpPost()
{
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('GET', 'http://www.yahoo.com', true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200) {
alert("Successful!");
}
}
self.xmlHttpReq.send();
}
xmlhttpPost();
</script>
I hope this will help you