无法在jquery中提交表单

时间:2015-10-23 07:55:58

标签: php jquery forms submit

我正在使用jquery smarty,php。我正在使用jquery验证表单,但提交按钮不起作用。 在checkemail.php中,我没有回应任何行;



$(document).ready(function() { //newly added 
  $("#formpge").submit(function(event) {
    event.preventDefault();
    var emailVal = $('#useremail').val();
    alert(emailVal);
    // assuming this is a input text field
    $.post("checkemail.php", {
      "useremail": emailVal
    }, function(data) {
      alert(data);
      if (data == 0) {
        alert("has to be added");
        $("#formpge")[0].submit();
      } else
        $("#useremail").focus();
    });

  });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form id="formpge" name="frmadduser" method="post">
  <div class="input1">
    <input type="text" placeholder="Your Full Name" id="username" name="username">
  </div>
  <div class="input2">
    <input type="text" placeholder="Your Email Address" id="useremail" name="useremail">
    <p color="blue" id="emailexist"></p>
  </div>
  <div class="input1">
    <input type="hidden" value="Y" name="active">
  </div>

  <div class="clear"></div>
  <div class="iwant_text2">
    <input type="submit" id="formsubmit" name="formsubmit" value="I Want One!">
  </div>
</form>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

尝试使用此代码: -

<form id="formpge" name="frmadduser" method="post">
  <div class="input1">
    <input type="text" placeholder="Your Full Name" id="username" name="username">
  </div>
  <div class="input2">
    <input type="text" placeholder="Your Email Address" id="useremail" name="useremail">
    <p color="blue" id="emailexist"></p>
  </div>
       <div class="input1">
    <input type="hidden" value="Y" name="active">
  </div>

  <div class="clear"></div>
  <div class="iwant_text2">
    <input type="submit" id="formsubmit" name="formsubmit" value="I Want One!" >
  </div>
  </form>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
  $(document).ready(function(){ //newly added 
$("#formpge").submit(function(event) {
event.preventDefault();
var emailVal = $('#useremail').val();
alert(emailVal);
// assuming this is a input text field
 $.post("checkemail.php", {"useremail" : emailVal}, function(data) {
    alert(data);
    if(data == 0){
    alert("has to be added");
    $("#formpge")[0].submit();
    }
    else 
    $("#useremail").focus();
 });

});
});
  </script>

try fiddle here

答案 1 :(得分:0)

首先要感谢mplungjan,Gaurav Srivastava和Strscream1984。问题是,在checkemail.php中我检查了isset($ _ REQUEST [&#39; formsubmit&#39;],但是这并没有设置只设置了文本字段。我不知道为什么没有设置类型提交。 再次,谢谢。