Mira,es bien facil, si tu quieres saber si el navegador soporta una aplicacion de tipo XMLHttpRequest, pues haces una funcion donde te diga eso, lo puedes hacer mas o menos asi: Código PHP: 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(); } else{ alert("Tu navegador no permite el uso de XMLHttpRequest");}
return xmlhttp; }
Y para lo del formulario q para guardar en la Base de Datos.. yo hice una prueba, pero solo hice un textbox, solo queria ver si funcionaba, y si,funciono, ahora solo falta agregarle los campos que tu desees: Código PHP: <center><form name ="myform" method="GET" onSubmit = "cargarContenido('bd.php?','contenedor');return false"> Ingresa tu nombre a la BD: <br><input type="text" id="texto1"> <br> <br><input type=submit value="ENVIAR" onPress="cargarContenido('bd.php?','contenedor')"> <input type="reset" name="Limpiar"> </form> </center>
Y esta es la funcion cargarContenido, el div indicado Código PHP: function cargarContenido(archivo,divID){ var contenedor; var nombre;
contenedor = document.getElementById(divID); contenedor.innerHTML = '<center> <img src="loader.gif" /> </center>'; nametext =document.myform.texto1.value; ajax=nuevoAjax(); if(archivo == URL){ ajax.open("GET","bd.php?"+"&"+"nombre="+nametext,true);} ajax.onreadystatechange=function() { if (ajax.readyState==4) { contenedor.innerHTML = ajax.responseText } } ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); ajax.send(null) }
Espero haberme explicado.. |