My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Cabeceras XMLHttpRequest</title>
<script>

var req;

function leer_doc(url) {

req = false;

// Llama objeto XMLHttpRequest
if (window.XMLHttpRequest) {
// Codigo para Firefox, Opera, IE7, etc.
req = new XMLHttpRequest();
/*if (req.overrideMimeType) {
req.overrideMimeType('text/xml');
}*/

// Si no funciona intenta utiliar el objeto IE/Windows ActiveX
} else if (window.ActiveXObject) {
// Código para IE5, IE6,...
req = new ActiveXObject("Microsoft.XMLHTTP");
}

if(req!=null){
req.onreadystatechange = procesarRespuesta;
req.open('GET',url,true);
req.send(null);
}

}

function cabeceras(){
// La URL no puede ser de un dominio distinto
url = "texto.txt"
leer_doc(url);
}

function procesarRespuesta(){

// Recuperamos el contenido del area de texto
sTexto = document.getElementById("texto").value;

if ((req.readyState == 4) && (req.status==200)) {
sTexto = sTexto + "Respuesta Procesada...\n";
sTexto = sTexto + req.getAllResponseHeaders();
document.getElementById("texto").value = sTexto;
}
}
</script>
</head>
<body>
<h1>Cabeceras XMLHttpRequest</h1>

<form id="formulario">
<p>
<textarea id="texto" name="texto" cols="40" rows="20">
</textarea>
</p>
<p>
<input type="button" onClick="cabeceras();"
value="Realizar Petici&oacute;n">
</p>
</form>

<br><br>
<hr>
Art&iacute;culo disponible en: <a href="http://lineadecodigo.com/2008/03/24/obtener-cabeceras-con-xmlhttprequest/">http://lineadecodigo.com/2008/03/24/obtener-cabeceras-con-xmlhttprequest/</a><br/>
<a href="http://lineadecodigo.com" title="Linea de Codigo">lineadecodigo.com</a>


</body>
</html>

Change log

r42 by vcuervo on Mar 23, 2008   Diff
Obtener las cabeceras mediante el objeto
XMLHttpRequest
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1987 bytes, 76 lines
Powered by Google Project Hosting