我正在为我的网站发表评论功能,并且需要使其在提交评论(并且包含错误)后才显示错误,而不刷新页面。我对AJAX/JQuery几乎一无所知,所以我需要一些帮助。在没有页面刷新的情况下显示错误
这是我到目前为止有:
<?php
if(isset($_POST['reply_submit'])) {
$reply = $_POST['new_reply'];
$reply_message = "";
if(empty($reply)) {
$reply_message = "Your comment is too short.";
}
}
?>
<html lang="en">
<body>
<form class="no-margin" method="POST" action="">
<textarea name="new_reply" placeholder="Write a reply..."></textarea>
<button name="reply_submit" class="btn post-button" type="submit">Post' . (isset($reply_message) ? '<div class="comment-warning">' . $reply_message . '</div>' : '') . '</button>
</form>
</body>
</html>
所以我需要做的是,如果人的评论框不符合标准(在这种情况下,空场),我需要它显示此错误行而不刷新页面:
<button name="reply_submit" class="btn post-button" type="submit">Post' . (isset($reply_message) ? '<div class="comment-warning">' . $reply_message . '</div>' : '') . '</button>
请帮助。
我很困惑,什么样的代码的URL的一部分一样。你能解释一下吗? –