1
我有一個表格;我使用jQuery發佈此表單,但現在我想知道如何在發佈完成後「重置」表單?後jQuery重置表單?
我jQuery和PHP代碼:
<?php
chdir('../');
include("_mysql.php");
include("_settings.php");
include("_functions.php");
chdir('admin');
if (isset($_POST['rubric'])) {
if (empty($_POST['rubric']) && empty($_POST['content'])) {
echo '<div class="alert alert-error alert-box">Du måste fylla i alla fält.</div>';
}
else {
$rubric = $_POST['rubric'];
$sql = "INSERT INTO ".PREFIX."news(`date`, `poster`)
VALUES('".time()."', '".$userID."')";
mysql_query($sql);
$id = mysql_insert_id();
$sql2 = "INSERT INTO ".PREFIX."news_contents(`newsID`, `headline`, `content`)
VALUES('".$id."', '".$rubric."', '".$_POST['content']."')";
mysql_query($sql2);
echo '<div class="alert alert-box alert-success">Klart, nyheten postad.</div>';
}
}
?>
$("#form").submit(function(event) {
event.preventDefault();
var poster = $.post('addnews.php', $(this).serialize());
poster.done(function(data) {
$(".result").html(data);
});
});
有誰知道我能做到這一點?因爲現在當我發佈一個新的標題和內容仍然存在,我真的不知道如何取消設置變量。
我真的還是想要我的錯誤,並且如果可能的話接受留言。
非常感謝您! :)完美的工作,我還有一個小問題,你知道我可以怎麼做才能顯示消息幾秒鐘? – Tommy
如果消息是你在'$(「。result」)。html(data)'行中顯示的內容,那麼:'setTimeout(function(){$(「。result」)。hide(); },3000);'會在3秒後隱藏這些元素。或者,您可以通過'.empty()'而不是'.hide()'將其設置爲空而不是隱藏。 –
非常感謝您的幫助! :) – Tommy