jQuery表单提交

时间:2010-11-22 19:29:33

标签: jquery

img="loader.gif (editeg link because i need 10 more reps to add img src tag)";

var pot=true;
function trimite(){
  if(pot==true){
   pot=false;
   jQuery("#loader").hide().html(img).slideDown();
   jQuery("#sec_code").fadeOut("slow");
   jQuery("#log_res").slideUp();
   jQuery.ajax({
    url:"register.php",
    type:"post",
    data:'utilizator='+jQuery("#utilizator").val()+'&parola='+jQuery("#parola").val()+'&reparola='+jQuery("#reparola").val()+'&mail='+jQuery("#mail").val()+'&security_code='+jQuery("#security_code_x").val(),
    success:function(msg){
     jQuery("#loader").hide().html(img).slideUp();
     jQuery("#log_res").hide().html(msg).slideDown();
     jQuery("#sec_code").html('<img style="margin-top: -2px;" src="captcha.php?'+Math.random()+'" />').fadeIn("slow");
     pot=true;
    }
   });
  } else return false;
 }

表格是:

编辑图片链接,无法发布img标签

当我点击提交时,我进入同一页面page.php?utilizator = somevalue&amp; pass = somevalue等,它不会在register.php上发出请求..为什么,我不知道,在js控制台,我无法加载资源,但它存在..它工作了一段时间,但我不知道我修改了什么,所以它不能成功运行.. 干杯,Edi。

2 个答案:

答案 0 :(得分:0)

<form onsubmit="javascript: return trimite();">
<input name="utilizator" type="text" class="password" id="utilizator" value="" size="32" maxlength="15">
<input name="parola" type="password" class="password" id="parola" value="" size="32" maxlength="30">
<input name="reparola" type="password" class="password" id="reparola" value="" size="32" maxlength="30">
<input name="mail" type="text" class="password" id="mail" value="" size="32" maxlength="40">
<img style="margin-top: -2px;" src="captcha.php" alt="ANTI SPAM !">
<input name="security_code" type="text" class="password" id="security_code_x" value="" size="5" maxlength="5">
<input type="submit" value="Inregistrare">
</form>

这是我用jquery函数trimite()提交的表单;我在函数之前加载了jquery v1.4.4。

答案 1 :(得分:0)

您需要在 案例中return false来阻止默认的提交行为......这就是正在发生的事情。确保从函数中的任何代码路径return false,否则它将执行正常的表单提交(就好像根本没有JavaScript)......就像你看到的一样。由于没有action属性,因此它会提交到同一页面。

所以这一部分:

 });
} else return false;

应该是这样的,所以它返回false,无论如何:

 });
}
return false;
相关问题