Noticias Weblogs Foros Wiki Código

RecorteX

399 usuarios y 231 recortes de código
Usuario

Contraseña
Crear cuenta
8 asp csharp css fechas Flash html imagenes java javascript linux mysql oracle php sql SQLServer vbnet web xhtml xml
Top Usuarios
fjmp76 (35)
albin (31)
josuebasurto (29)
juanjo (29)
pedrocaro (9)
stanz (8)
AndiXTRM (7)
Joserra (7)
miiglesi (6)
aplyca (5)
Top Etiquetas
php (38)
vbnet (27)
javascript (26)
html (25)
java (22)
sql (17)
csharp (16)
mysql (13)
xml (13)
css (10)
Flash (7)
imagenes (7)
xhtml (7)
fechas (6)
linux (6)
asp (6)
oracle (5)
SQLServer (5)
web (4)
8 (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 - Información legal y técnica