Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/04/2012, 11:56
ARAPSPGON
 
Fecha de Ingreso: octubre-2007
Mensajes: 57
Antigüedad: 16 años, 7 meses
Puntos: 0
Pregunta Submit y funcion ajax no funcionan

Buenas, tengo este ejercicio y por mucho que he probado el ajax no funciona correctamente. lo he revisado muchas veces y no entiendo porqué el ajax no funciona correctamente.

¿será que la función submit es incompatible con la función ajax?

gracias

Código PHP:
<script type="text/javascript">
        $(
document).ready(function(){

           $(
"#f1").submit(function(){

                $.
ajax({
                    
type "POST",
                    
url : $(this).attr("action"),
                    
data : $(this).serialize(),
                    
dataType"html",
                    
beforeSend: function(){
                        $(
"#principal").fadeOut();
                        $(
"#carga").fadeIn();
                    },
                    
success: function(data){
                        $(
"#carga").fadeOut();
                        $(
"#principal").fadeIn();
                        
alert(data);
                    }
                })     

           })
               
        })
    
</script>
</head>
<body>
    <div id="principal">
        
        <form id="f1" method="post" action="procesar.php">
            <label for="idname">Nombre</label> 
            <input type="text" name="idname" id="idname" value="" /> 

            <label for="idemail">E-Mail</label> 
            <input type="text" name="idemail" id="idemail" value="" />
            
            <input type="submit" name="entrar" value="Entrar" /> 
        </form>
    </div>

    <div id="carga">
            <img src="img/ajax-loader.gif" /> Cargando...
    </div>
</body> 
procesar.php

Código PHP:
<?php
if(isset($_POST["entrar"])){
    
$idname $_POST["idname"];
    
$idemail $_POST["idemail"];
    
sleep(2);
    echo 
"$idname datos procesados";
}
?>