我的 JavaScript 文件中有这个。我知道它被称为:
var data = "hi";
$.ajax({
type: "POST",
url: "../register_email.php",
data: data,
success: function(data) {
alert("worked!");
},
error: function(jqXHR, textStatus, errorThrown) {
alert("NOPE");
$(".contact-form").hide();
$(".alt-contact").hide();
// Inserts divs making up the success message for the form submission
$(".contact-form").html("<div class='error-message'><div class='error-image'></div><div class='error-title'>Whoops! An error occurred.</div><div class='error-body'>That's strange... Please <a href='mailto:support@syllableapp.com'>email me</a> instead. Sorry about that.</div></div>");
$(".contact-form").fadeIn(500);
}
});
它调用这个 PHP 文件:
<?php
$db = new mysqli("localhost", "name", "pass", "db");
if ($db->connect_error) {
echo "Could not connect to database.";
exit;
}
else {
$db->query("INSERT INTO emails (email) VALUES ('trying')");
echo 1;
}
?>
但它从不做任何事情。它只是提醒我“不”。我只是希望它添加行,但是当我检查我的服务器时,它永远不会这样做。但是,如果我只是在浏览器中导航到 register_emails.php,它会加载并添加它。