Comunidad de diseño web y desarrollo en internet online

Ajax y envio de formulario... Como?

Citar            
MensajeEscrito el 13 Mar 2007 09:43 am
Hola, tengo una pagina con un div donde cargo un include con un formulario, todo esto por ajax. Para renviar los datos del formulario y que se me carge dentro de div utilizo el tutorial que e visto en esta web, pero no me funciona o no se aplicarlo, el codigo lo meto en un js:

Código :

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 autor,titulo,texto, contenedor;
   contenedor = document.getElementById('detalles');

   //for(i=0; i<document.forms.elements.length; i++)
   //{
      autor = document.getElementById('autor').value;
      titulor = document.getElementById('titulo').value;
      texto = document.getElementById('texto').value;      
   //}
   
   ajax=nuevoAjax();
   ajax.open("POST","foro.php",true);
   ajax.onreadystatechange=function() 
   {
      if (ajax.readyState==4) 
      {
         contenedor.innerHTML = ajax.responseText
       }
      else 
      {
         detalles.innerHTML = '<img src="loading.gif" align="absmiddle" /> Cargando...';
     }
   }
   ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   ajax.send("autor=" + autor + "& titulo =" + titulo + "& texto =" + texto);
}


y luego el formulario, como invocaria la function???


<form action="javascript:cargarContenido()" method="post">


Esto haria que se me cargase la pagina foro.php dentro del div detalles???? a ver si alguien me puede ayudar con esto, gracias de antemano

bichomen

Por bichomen

0 de clabLevel



Genero:Masculino  

msie
Citar            
MensajeEscrito el 13 Mar 2007 02:43 pm
seguramente, sólo un detalle.
"action" se refiere a dónde va a ir el formulario, no estoy seguro qué haga con un javascript ahí, pero si alguien tiene js desactivado se va a joder todo.
en todo caso sería así

Código :

<form action="foro.php" method="POST" onsubmit="cargarContenido(); return false;" >


listo. suerte.

Por fael

BOFH

2443 de clabLevel

3 tutoriales
2 articulos

 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.