Noticias Weblogs Foros Wiki Código

RecorteX

326 usuarios y 203 recortes de código
Usuario

Contraseña
Crear cuenta
asp csharp css fechas fichero Flash html imagenes java javascript linux mysql oracle php ruby sql SQLServer vbnet xhtml xml
Top Usuarios
albin (29)
josuebasurto (28)
fjmp76 (27)
juanjo (25)
pedrocaro (9)
AndiXTRM (7)
Joserra (7)
miiglesi (6)
aplyca (5)
moisesmarquez (5)
Top Etiquetas
php (38)
html (24)
javascript (20)
vbnet (20)
java (19)
sql (15)
mysql (13)
csharp (12)
xml (10)
css (8)
Flash (7)
xhtml (7)
imagenes (7)
asp (6)
linux (6)
fechas (6)
SQLServer (5)
oracle (5)
fichero (4)
ruby (4)

Peticiones POST por XMLHttpRequest

Primero debemos obtener la referencia al objeto XMLHttpRequest
 
  function getHTTPObject() 
	{ var xmlhttp; 
		/*@cc_on @if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @else xmlhttp = false; @end @*/ 
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
		{ try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } }
		return xmlhttp; 
	} 
	var http = getHTTPObject(); // We create the HTTP Object
 
Y para poder realizar la petición mediante POST es importante la siguiente linea de enconding:
 
http.open("POST", url, true);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
http.onreadystatechange = handleHttpResponse;
 
Siendo "handleHttpResponse" la función que queramos que trate la respuesta.
 
function handleHttpResponse() 
{
	if (http.readyState == 4) 
	{
		results = http.responseText;
               //tratar la respuesta contenida en results.
	}
}
 
Identifícate para dejar un comentario.
info@recortex.com - Proyecto: Juanjo Navarro, 2006 - Diseño: Albin