Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/12/2011, 18:33
callesstone2
 
Fecha de Ingreso: diciembre-2011
Ubicación: Buenos aires
Mensajes: 14
Antigüedad: 13 años, 2 meses
Puntos: 0
Pregunta Envio formulario con ajax

Hola como les va, vuelvo con mis problemillas en ajax cosa que nuevamente no logro ver su Error.

Lo que hice es un formulario algo simple, paso este por ajax llegando a php...
pero el tema es que no me envia ni me informa de los estados ( onreadystatechange )

EL PHP , SI LO ABRO EN EL NAVEGADOR CON LAS VARIABLES FUNCIONA POR ENDE EL ERROR ESTA EN JS


Código HTML:
Ver original
  1. <form onSubmit="Enviar();">
  2. Interprete:<br>
  3. <select id="Interprete">
  4. <? include("Select.php"); ?>
  5. Titulo<br>
  6. <input type="text" id="Titulo"  placeholder="Ingresa el nombre del disco" /><br>
  7. Caratula:<br>
  8. <input type="url" id="Imagen"   placeholder="Ingresa la url de la caratula"/><br>
  9. Año:<br>
  10. <input type="number" id="Ano"  placeholder="Año" /><br>
  11. Velocidad:<br>
  12. <input type="number" id="Velocidad"  placeholder="Velocidad" /><br>
  13. Servidor:<br>
  14. <input type="text" id="Servidor"  placeholder="Ej:Megaupload,rapidshare..."/><br>
  15. Sello:<br>
  16. <input type="text" id="Sello"  placeholder="El sello discografico" /><br>
  17. Descarga:<br>
  18. <input type="url" id="Descarga" placeholder="El link de descarga"/>
  19. <Estados id="Estados"></Estados>
  20. <input type="submit" name="Enviar" value="Enviar"/>  <input type="button" onClick="Previsualizar(); return true;" value="Previsualizar" />
  21. </form>

Código Javascript:
Ver original
  1. function Enviar(){
  2.    
  3.     var id = document.getElementById('Interprete').value;
  4.     var Interprete1 = document.getElementById('Interprete').selectedIndex;
  5.     var Interprete = document.getElementById('Interprete').options[Interprete1].text;
  6.    
  7.     var Titulo = document.getElementById('Titulo').value;
  8.     var Ano = document.getElementById('Ano').value;
  9.     var Velocidad = document.getElementById('Velocidad').value;
  10.     var Servidor = document.getElementById('Servidor').value;
  11.     var Sello = document.getElementById('Sello').value;
  12.     var Descarga = document.getElementById('Descarga').value;
  13.     var Imagen  = document.getElementById('Imagen').value;
  14.  
  15.    
  16.     // --- Variables ajax
  17.     var ajax = new XMLHttpRequest();
  18.    
  19.     /* Estados */
  20.     ajax.onreadystatechange=function(){
  21.        
  22.         /* Si se esta cargando */
  23.         if(ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3){
  24.         document.getElementById('Estados').innerHTML='Procesando su peticion...';
  25.         }
  26.         /* Si se cargo */
  27.         if(ajax.readyState==4 && ajax.status==200){
  28.         document.getElementById('Estados').innerHTML=ajax.responseText;
  29.         }
  30.     }
  31.    
  32.     // --- Envios---
  33.     ajax.open("POST","Enviar.php?id="+id+"&Interprete="+Interprete+"&Titulo="+Titulo+"&Ano="+Ano+"&Velocidad="+Velocidad+"&Servidor="+Servidor+"&Sello="+Sello+"&Descarga="+Descarga+"&Imagen="+Imagen,true);
  34.  
  35.     ajax.send();
  36.    
  37. }

Código PHP:
Ver original
  1. <?
  2. // --- Conexion mysql ---
  3. $Conexion = mysql_connect('localhost','root','lamocosa');
  4. mysql_select_db('ajax',$Conexion);
  5.  
  6. // --- Variables ---
  7. $Id = $_GET['id'];
  8. $Interprete = $_GET['Interprete'];
  9. $Titulo = $_GET['Titulo'];
  10. $Ano = $_GET['Ano'];
  11. $Imagen = $_GET['Imagen'];
  12. $Velocidad = $_GET['Velocidad'];
  13. $Servidor = $_GET['Servidor'];
  14. $Sello = $_GET['Sello'];
  15. $Descarga = $_GET['Descarga'];
  16.  
  17. // --- Insercion mysql ---
  18. $Envio = mysql_query("INSERT INTO album (indentificador,id,Interprete,Imagen,Titulo,Ano,Velocidad,Servidor,Sello,Descarga, Usuarios,Valores,Megusta) VALUES ('','".$Id."','".$Interprete."', '".$Imagen."','".$Titulo."', '".$Ano."', '".$Velocidad."', '".$Servidor."', '".$Sello."', '".$Descarga."', '0', '0', '1');");
  19.  
  20. // --- Si Esta bien el envio ---
  21. if($Envio){
  22.     echo 'El album se acabo de crear vease';   
  23.     }
  24.  
  25.  
  26. // --- Cerrando mysql ---
  27. mysql_close($Conexion);