[英]PHP result how to pass ajax success function
I'm not getting success message from ajax which I called in success function. 我没有从我在成功函数中调用的ajax收到成功消息。 Please check the code of my index.php , contact-form-script.js and form-process.php
请检查我的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);
}
}
});
}
Do changes like below in your code : 在您的代码中进行如下更改:
//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";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.