我使用ajax和jquery提交我的表单,但问题是每次表单提交时都会重复出现错误消息。可能是什么问题呢 ?
js file
$(document).ready(function(e){
$("#checkit").click(function(){
var ID = $("#certcode").val();
$.ajax({
type: "POST",
url: "/icac/cert-check-ajax.php",
data: 'z='+ ID,
success: function(data) {
$("#datadisp").append(data);
$('#certcode').val('');
return false;
}
});
});
});
php
<?php
include('/includes/db-connect.php');
if (!empty($_POST["z"]) ) {
$z = $_POST["z"];
$result=mysqli_query($con,"SELECT * FROM `certificate_acheived_tbl` WHERE `cert_check_code` = '$z'");
if( mysqli_num_rows($result) == 1) {
echo '<div id="datadisp" class="alert alert-success" role="alert">Certificate Found</div';
}
else { echo '<div id="datadisp" class="alert alert-warning" role="alert">Invalid Security Code</div>';}
}
?>
答案 0 :(得分:0)
我解决了 $( “#datadisp”)空()。 $( “#datadisp”)HTML(数据);