當你是一個初學者,我覺得最簡單的方式將是我會描述的一個。 如果你有這個div(您希望新的飼料出現):
標記:
<div id="feeds">
<div class="feed"> Feed 1</div>
<div class="feed"> Feed 2</div>
<!-- Your new feed will appear here -->
</div>
的Javascript:
$("div.feed:last").clone().appendTo("#feeds").load("newfeed.php?param1=val1");
服務器(asuming PHP):
<? //newfeed.php
$param1 = $_GET['param1'];
$content = "Here put your latest feed";
echo $content;
?>
就是這樣。
現在,我要解釋一下我們的JavaScript線
$("div.feed:last") //Select the last div with class "feed"
.clone() //We clone it, to make space for the new feed
.appendTo("#feeds") //We add the clone to the final of the feed list
.load("newfeed.php?param1=val1"); //Load it's content with a value got from server
當你覺得使用jQuery更舒適,使用$就不是在做什麼。 希望這可以幫助,歡呼
你可以發佈你的標記?或者在[JS Fiddle](http://jsfiddle.net/)上發佈一些東西來展示你的使用? – 2011-05-01 20:47:41
是的,使用jQuery和'$ .post()'。如果你無法正常工作,請使用你試過的代碼回到這裏,我相信有人會幫你調試它。 http://api.jquery.com/jQuery.post/供參考。 – ggutenberg 2011-05-01 20:49:27
@David我沒有標記,我有一個簡單的表單,在數據庫中插入一條消息,並在其下方顯示消息列表。很簡單。但每次提交後頁面都會重新加載。我不想重新加載,但我希望消息列表在提交後立即刷新。 – 2011-05-01 21:02:09