我正在使用自提交表單來處理數據,但我現在需要分別處理它,所以現在我需要提交表單,返回結果並將其放入div 。看來使用AJAX
是一種很好的方法,可以將數據返回到表單所在的原始頁面。我已經看了很多例子,並且我不太瞭解如何去做或者真的如何去做。通過Ajax提交表單並更新結果div
假設我想將此表單數據從index.php
發送到我的流程頁面twitterprocess.php
我需要做什麼並使其返回以顯示處理的數據。
<form method="POST" action="twitterprocess.php">
Hashtag:<input type="text" name="hashtag" /><br />
<input type="submit" value="Submit hashtag!" />
</form>
這就是我一直用來顯示結果。
<?php foreach($results as $result) {
$tweet_time = strtotime($result->created_at);?>
<div>
<div class="tweet"> <?php echo displayTweet($result->text),"\r\n"; ?>
<div class="user"><?php echo "<strong>Posted </strong>" . date('j/n/y H:i:s ',$tweet_time) ?><strong> By </strong><a rel="nofollow" href="http://twitter.com/<?php echo $result->from_user ?>"><?php echo $result->from_user ?></a></div>
</div>
<br />
<? } ?>
我是新來的AJAX,但任何指導,將不勝感激
感謝這個好例子。我會投票,但唉,我的排名太低 – user1711576
一個問題。什麼是200的? '如果(xmlhttp.readyState == 4 && xmlhttp.status == 200){' – user1711576
200意味着狀態爲「OK」,即AJAX函數已經得到了所需要的,4表示對服務器的請求正確完成並且響應來自該服務器已準備好使用。 – Isank