Ver Mensaje Individual
  #8 (permalink)  
Antiguo 22/02/2006, 07:45
ostricajh
 
Fecha de Ingreso: octubre-2005
Mensajes: 45
Antigüedad: 18 años, 7 meses
Puntos: 0
Siguiente Cuestión Parte Uno, Parte Dos a continuación.......


Hola amigos del foro, estos son los dos códigos que estoy utilizando para el manejo de Ajax.
Este es archivo donde se encuentran las funciones de Ajax, adicione la función escape, como se verá en el código.

Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Ajax: Ejemplo 3 - Envío de datos por el método POST</title>
</head>
<script>
function nuevoAjax()
{
	var xmlhttp=false;
	try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} 	
	catch (e) 
	{
	  try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} 	
	  catch (E) {xmlhttp = false;}
 	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
  		xmlhttp = new XMLHttpRequest();
return xmlhttp;
}

function cargarContenido()
{
	var t1, t2, contenedor;
	var contenedor = document.getElementById('contenedor');
	var t1 = escape(document.getElementById('texto1').value);
	var t2 = escape(document.getElementById('texto2').value);
	ajax=nuevoAjax();
	ajax.open("GET", "ejemploajax2.php?t1="+t1+"&t2="+t2+"&id=1",true);
	ajax.onreadystatechange=function() 
	{
		if (ajax.readyState==4) 
			contenedor.innerHTML = ajax.responseText;
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("t1="+t1+"&t2="+t2+"&id=1");
}
window.onload= function(){cargarContenido()}
</script>
<style type="text/css">
#contenedor{
border: 1px solid #f00;
padding: 10px;
margin: 14px;
}
</style>
<body>
<form onSubmit="cargarContenido(); return false">
<div><input type="text" id="texto1" value="valor1" /></div><div id="res">Corregir</div>
<div><textarea id="texto2">texto en el textarea</textarea></div>
<div><input type="submit" value="enviar" onPress="cargarContenido()" />
<input type="button" value="enviar" onPress="javascript:form1.jorge.value='Hola';" />
</div>
</form>
Este ejemplo enviará información por el método post y la pondrá en el siguiente div:
<div id="contenedor">div contenedor</div>
</body>
</html>