我正在尝试将表单数据发送到php代码一些如何在我有条件的情况下如果提交按钮执行以下代码它不起作用:
$("button#send").click(function() {
var error = '';
var send = $("#send").val() = true;
if ($('#username').val().length == 0) { error += 'user name<br />'; }
if ($('#password').val().length == 0) { error += 'password<br />'; }
if ($('#repassword').val().length == 0) { error += 'repassword<br />'; }
if ($('#password').val() != $('#repassword').val()) { error += 'pass match<br />'; }
var phonenum = $('#phonenum').val() + $('#select').val();
if (phonenum.length == 0) { error += 'phone num <br />'; } else if ($.isNumeric(phonenum) == false || phonenum.length != 10) { error += 'phoneworng<br />'; }
if (error != '') {
$('#result').html(error);
} else {
$.ajax({
url: $("#form_reg").attr('action'),
data: $("#form_reg input").serializeArray(),
type: 'POST',
success: function(result) {
$("#result").html(result);
},
error: function(error) {
alert(error);
}
});
}
$("#form_reg").submit(function(e) {
e.preventdefault;
return false;
});
});
这里是html代码
<form id="form_reg" action="AddUser.php" method="post">
<div class="head_div"> <span> reg </span> </div>
<div id="main_reg">
<div class="login_line">
<label for="username">username</label>
<input type="text" name="username" id="username" placeholder="username" />
</div>
<div class="login_line">
<label for="password"> passs </label>
<input type="password" name="password" id="password" placeholder="pass" />
</div>
<div class="login_line">
<label for="repassword"> repass </label>
<input type="password" name="repassword" id="repassword" placeholder="repass" />
</div>
<div class="login_line">
<label for="email"> email </label>
<input type="email" name="email" id="email" placeholder="email" />
</div>
<div class="login_line">
<label for="phonenum"> phone num</label>
</div>
<div class="login_line">
<input type="text" id="phonenum" name="phonenum" placeholder="phone num" />
<select id="select">
<option value="050"> 050</option>
<option value="054"> 054</option>
<option value="052"> 052</option>
<option value="053"> 053</option>
<option value="058"> 058</option>
</select>
</div>
</div>
<div class="login_line">
<div id="result"> </div>
</div>
<div class="send_line">
<button type="submit" name="send" id="send"> reg</button>
</div>
</form>
这里是php
include_once 'login_db.php';
$error_msg="";
if(isset($_POST['send']))
{
其余部分包括回声,而不是if isset($_POST['send'])
代码是回显结果