jQuery
$(function() {
$(
"#contactForm input,#contactForm textarea,#contactForm button"
).jqBootstrapValidation({
preventSubmit: true,
submitError: function($form, event, errors) {
// additional error messages or events
},
submitSuccess: function($form, event) {
event.preventDefault(); // prevent default submit behaviour
var cnumber = $("input#cnumber").val();
var cname = $("input#cname").val();
var cemail = $("input#cemail").val();
var cmessage = $("textarea#cmessage").val();
$this = $("#sendMessageButton");
$this.prop("disabled", true);
$.ajax({
url: "/xcrawl/mail/contact.php",
type: "POST",
data: {
myname: cname,
mynumber: cnumber,
myemail: cemail,
mymessage: cmessage,
},
cache: false,
success: function(response) {
// document.write(response);
alert("Please" + response.substring(0, 1));
if (response.substring(0, 1) == 1) {
$("#csuccess").html("<div class='alert alert-success'>");
$("#csuccess > .alert-success")
.html(
"<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×"
)
.append("</button>");
$("#csuccess > .alert-success").append(
"<strong>Thank You for Contacting Us.<br>You will get back to you within 24 Hours<strong>"
);
$("#csuccess > .alert-success").append("</div>");
//clear all fields
$("#contactForm").trigger("reset");
} else {
$("#csuccess").html("<div class='alert alert-success'>");
$("#csuccess > .alert-success")
.html(
"<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×"
)
.append("</button>");
$("#csuccess > .alert-success").append(
"<strong>Something went wrong.<br>Please try again later<strong>"
);
$("#csuccess > .alert-success").append("</div>");
//clear all fields
$("#contactForm").trigger("reset");
}
},
error: function() {
// Fail message
$("#success").html("<div class='alert alert-danger'>");
$("#success > .alert-danger")
.html(
"<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×"
)
.append("</button>");
$("#success > .alert-danger").append(
$("<strong>").text(
"Sorry " +
firstName +
", something went wrong. Please try again later!"
)
);
$("#success > .alert-danger").append("</div>");
//clear all fields
$("#contactForm").trigger("reset");
},
complete: function() {
setTimeout(function() {
$this.prop("disabled", false); // Re-enable submit button when AJAX call is complete
}, 1000);
},
});
},
filter: function() {
return $(this).is(":visible");
},
});
$('a[data-toggle="tab"]').click(function(e) {
e.preventDefault();
$(this).tab("show");
});
});
/*When clicking on Full hide fail/success boxes */
$("#name").focus(function() {
$("#success").html("");
});
PHP文件
<?php
$host = "SOME_HOST";
$username = "SOME_NAME";
$password = "SOME_PASSWORD";
$connection = mysqli_connect($host, $username, $password);
$name = strip_tags(htmlspecialchars($_POST['myname']));
$email_address = strip_tags(htmlspecialchars($_POST['myemail']));
$number = strip_tags(htmlspecialchars($_POST['mynumber']));
$message = strip_tags(htmlspecialchars($_POST['mymessage']));
if(!$connection)
die("Error : " . mysqli_error());
$DBQuery = "USE MY_DB";
mysqli_query($connection, $DBQuery);
$Query = "MY_QUERY";
if(mysqli_query($connection, $Query))
echo json_encode (1);
else
echo json_encode (2);
mysqli_close($connection);
?>
这在我的本地主机上运行良好,并且在3天前也可以在我的服务器上运行良好。 我购买了SSL,并将网站设为https。我确定那是原因,因为不可能有其他任何原因使其可以在localhost而不是服务器上运行。但即时通讯不使用任何http链接。那么,为什么它不能在我的服务器上运行呢? 根据我的php代码,响应代码应为1或2,但即时通讯会获取整个php文件。请帮帮我
编辑 Index.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"></script>
<!-- Third party plugin JS-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js"></script>
<!-- Contact form JS-->
<script src="xcrawl/mail/jqBootstrapValidation.js"></script>
<script src="xcrawl/mail/contact_me.js"></script>
<!-- Core theme JS-->
<script src="xcrawl/js/scripts.js"></script>