我正在爲我的網站發表評論功能,並且需要使其在提交評論(並且包含錯誤)後才顯示錯誤,而不刷新頁面。我對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的一部分一樣。你能解釋一下嗎? –