我没有从ajax获得成功消息,我在成功函数中调用了该消息。 请检查我的 index.php , contact-form-script.js 和 form-process.php
的代码 $("#contactForm").validator().on("submit", function (event) {
if (event.isDefaultPrevented()) {
// handle the invalid form...
formError();
submitMSG(false, "Did you fill in the form properly?");
} else {
// everything looks good!
event.preventDefault();
submitForm();
}
});
function submitForm(){
// Initiate Variables With Form Content
var name = $("#sugname").val()
var email = $("#sugemail").val();
var mobile = $("#sugmobile").val();
var message = $("#sugmessage").val();
$.ajax({
type: "POST",
url: "form-process.php",
data: "name=" + name + "&email=" + email + "&mobile=" + mobile + "&message=" + message,
success : function(text){
if (text == "success"){
formSuccess();
} else {
formError();
submitMSG(false,text);
}
}
});
}
答案 0 :(得分:0)
进行如下更改:
//if errormsg not empty
if(!empty($errorMSG)){
//print
echo $errorMSG;
}else{
//execute query
include('dbconfig.php');
$sql="insert into suggestions(name,contactno,mailid,jfsuggestion) values
('".$name."','".$mobile."','".$email."','".$message."')";
$success = mysqli_query($conn, $sql);
if($success){
echo "success";
}
}