php - Cancel submit jquery -
this part of code form requesting data check if email alredy exist. thing is, program supposed return 0 if there no mail this. dont work properly, because program keep sending data, if mail not correct.
if want more info, or missing let me know. in advance.
$(document).ready(function () { $("#enviar").click(function(e) { e.preventdefault(); var error = false; consulta = $("#email2").val(); $.ajax({ type: "post", url: "compruebaemail.php", data: "b="+consulta, datatype: "html", error: function(){ alert("error peticiĆ³n ajax"); }, success: function(data){ if(data==0){ $("#error").html("email incorrecto"); error = false; }else{ $("form").unbind('submit').submit(); } } }); if (error){ return false; } }); });
and here compruebaemail.php
<?php require_once('connections/vinoteca.php'); ?> <?php mysql_select_db($database_vinoteca, $vinoteca); $user = $_post['b']; if(!empty($user)) { comprobar($user); } function comprobar($b) { $sql = mysql_query("select * usuarios email = '".$b."'"); $contar = mysql_num_rows($sql); if($contar == 0){ echo 0; }else{ echo 1; } } ?>
and here goes post
<form method="post" name="form1" action="validarusu.php"> <div class="row"> <span class="center">email</span> </div> <div class="row"> <input type="text" name="email" id="email2" value="" size="32" /> </div> <div class="row"> <span class="center">contraseña</span> </div> <div class="row"> <input type="password" name="password" id="id2" value="" size="32" /> </div> <div class="row"> <span id="error"> </span> </div> <div class="row"> <input type="submit" value="acceder" id="enviar" size="20"> </div> <div class="row"> <a href="recuperarpassword.php">recuperar contraseña</a> </div> </form>
the problem you're returning false
ajax function. need return false click
function. give try:
$("#enviar").click(function() { var error = false; consulta = $("#email2").val(); $.ajax({ type: "post", url: "compruebaemail.php", data: "b="+consulta, datatype: "html", error: function(){ alert("error peticiĆ³n ajax"); }, success: function(data){ if(data==0){ $("#error").html("email incorrecto"); error = true; } } }); if (error) return false; });
Comments
Post a Comment