Ver Mensaje Individual
  #20 (permalink)  
Antiguo 15/11/2006, 11:43
Avatar de chalchis
chalchis
 
Fecha de Ingreso: julio-2003
Mensajes: 1.773
Antigüedad: 20 años, 10 meses
Puntos: 21
aqui va todo el codigo

//index.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javascript" src="ajax.js"></script>
<title>Documento sin t&iacute;tulo</title>
</head>

<script language="Javascript">
//Función para guardar tu informacion en bd utilizando ajax.
function cargarContenido() {
if (parseInt(navigator.appVersion)>3) {
if (navigator.appName=="Netscape") {
winW2 = window.innerWidth;
winH2 = window.innerHeight;
}

if (navigator.appName.indexOf("Microsoft")!=-1) {
winW2 = document.documentElement.offsetWidth;
winH2 = document.documentElement.offsetHeight;
}
}

var miAjaxObj = MyAjax();
miAjaxObj.open("GET", "proceso.php?ancho=" + winW2 + "&alto=" + winH2, true);
miAjaxObj.onreadystatechange = function() {
if (miAjaxObj.readyState == 4) {
if (miAjaxObj.status == 200) {
var resultado = miAjaxObj.responseText;
alert("Respuesta con HTML\n" + resultado);
resultado = ClearHTML(resultado);
alert("Respuesta sin HTML\n" + resultado);
} else {
alert("Error Número: " + miAjaxObj.status + "\nDescripción: " + miAjaxObj.statusText);
}
} else {
//aqui pones algo para que se vea el loading..... una imagen, un texto.. lo que quieras.
}
}

miAjaxObj.send(null);
}
</script>

<body onLoad="cargarContenido()">

</body>
</html>

//proceso.php
<?php
header('Content-Type: text/xml; charset=ISO-8859-1');
echo '<?xml version="1.0" encoding="ISO-8859-1"?>';

if (count($_GET) > 0) {
$ancho = isset($_GET["ancho"]) ? $_GET["ancho"] : 0;
$alto = isset($_GET["alto"]) ? $_GET["alto"] : 0;

$sSQL = "insert into tabla resolucion(ancho,alto) values($ancho, $alto)";
//aqui va tu codigo php de coneccion a la base de datos... etc etc etc...

echo("La resolución se guardó correctamente. ($ancho x $alto)");
}
?>

//ajax.js

/************************************************** **************
* Funciones de JavaScripts
* Ezequiel Villarreal G. 2005, Todos los derechos reservados.
************************************************** ***************/


//Función principal para trabajar con AJAX
function MyAjax() {
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 ClearHTML(sHTML) {
sHTML = sHTML.replace(/<[^>]*>/gi, "");
sHTML = sHTML.replace( /\n/gi, "") ;
sHTML = sHTML.replace(/&nbsp;/gi, "");

return sHTML;
}

saludos
__________________
gerardo