从jquery调用php验证文件

时间:2017-08-03 07:37:33

标签: javascript php jquery html

HTML代码:

我已经使用jquery进行了验证。现在我的下一个任务是从jquery调用php文件,并在page2.php中进行验证,然后将其提交到数据库。完成数据库提交后,调用index.php。但我在这里遇到的问题是,当我从jquery调用page2.php时,没有任何事情发生。 IT不会把我带到那里。有谁可以帮我解决这个问题。

$(document).ready(function() {
  $("#errorBox").html("Hello1243 by JQuery");
  $("#reg").click(function(e) {


    //document.write("Name="+name);
    var email = $("#eml").val();
    var pwd = $("#pwd").val();
    var cpassword = $("#cpwd").val();


    if (email == '' || pwd == '' || cpassword == ''

    ) {
      e.preventDefault();
      $("#errorBox").html("Please fill in all the fields. All the * marked fields are important");
      //alert("Please fill in all fields");
    } else if ((password.length) < 8) {
      e.preventDefault();
      $("#errorBox").html("Password must be atleast 8 character long");
      //document.getElementById("errorBox").innerHTML = ;
    } else if (!(password).match(cpassword)) {
      e.preventDefault();
      $("#errorBox").html("Password don't match");
      //document.getElementById("errorBox").innerHTML = ;
    } else if (IsEmail(email) == false) {
      e.preventDefault();
      $("#errorBox").html("Please enter correct email id");

    } else {
      e.preventDefault();

      $.ajax({
        type: "POST",
        url: "page2.php",
        data: jQuery("#my_form").serialize(),
        cache: false,
        success: function(data) {
          alert(data);
          /*if json obj. alert(JSON.stringify(data));*/
        },
        error: function() {
          alert("error");
        }
      });



    }

  });


});

function IsEmail(email) {
  var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (!regex.test(email)) {
    return false;
  } else {
    return true;
  }
}
sup {
  color: red;
}

.paddi {
  padding: 10px;
}

input[type="text"] {
  width: 300px;
}

input[type="password"] {
  width: 300px;
}

.mar {
  margin-top: 100px;
}

#errorBox {
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">

  <div class="col-md-offset-6 col-md-6 paddi">
    <a href="#"><button class="btn btn-lg"><strong>Already a member. Please Sign In</strong></button>
    </a>
  </div>

  <div class="mar">

    <form class="form-horizontal" id="my_form" role="form" method="POST" action="#">

      <div class="panel panel-primary">
        <div class="panel-heading text-center">
          <h4>
            Become a member now. Register with us for free
          </h4>
        </div>

        <div class="panel-body">
          <div id="errorBox"></div>

          <div class="page-header paddi">
            <h4>
              Create Login Details
            </h4>
          </div>
          <div class="form-group row">

            <label class="control-label col-md-3 text-right" for="email"> Enter your Email id<sup>*</sup>:
    </label>

            <div class="col-md-7">
              <input type="text" name="eml" id="eml" />
            </div>
          </div>

          <div class="form-group">
            <label class="control-label col-md-3 text-right" for="pwd">
    Password<sup>*</sup> :
    </label>

            <div class="col-md-7">
              <input type="password" name="pwd" id="pwd" />
            </div>
          </div>

          <div class="form-group">
            <label class="control-label col-md-3 text-right" for="cpwd">
    Confirm Password<sup>*</sup> :
    </label>
            <div class="col-md-7">
              <input type="password" name="cpwd" id="cpwd" />
            </div>
          </div>
          <div class="form-group">

            <label class="control-label col-md-3 text-right" for="el">
    Upload your Resume Document <sup>*</sup> :
    </label>
            <div class="col-md-7">
              <input id="lefile" type="file" style="display:none">
              <div class="input-append">
                <input id="photoCover" class="input-large" type="text">
                <a class="btn btn-primary" onclick="$('input[id=lefile]').click();">Browse</a>
              </div>

              <script type="text/javascript">
                $('input[id=lefile]').change(function() {
                  $('#photoCover').val($(this).val());
                });
              </script>
            </div>
          </div>
          <div class="control-group">
            <!-- Button -->
            <div class="controls col-md-offset-3 col-md-2">
              <button class="btn btn-success" id="reg">Register</button>
            </div>
          </div>
        </div>
      </div>

    </form>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

您的AJAX请求中存在问题。您没有正确发送df=s.groupby(s.index.str.count('\.')).sum().rename(d).rename_axis('a') \ .iloc[1:].iloc[::-1].cumsum().iloc[::-1].rename_axis('a').reset_index(name='b') print (df) a b 0 1 46.38 1 1.1 34.10 2 1.1.1 17.68 ,它应该是:

data