嗨我試圖學習如何使用下面的簡單示例來發布帖子請求。雖然我可以輕鬆地將數據發佈到result.php並通過警報消息返回結果,但我希望將結果返回到當前頁面的div中。原因是我希望用戶在點擊按鈕後立即看到他們的姓名出現在屏幕上。有人能告訴我如何修改此代碼,以便文章的結果以div顯示,而不是作爲警報消息顯示?由於在div中顯示jquery發佈數據
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#searchForm").submit(function(event){
$.post("result.php",
{
name:"Mike"
},
function(data,status){
//alert("Data: " + data + "\nStatus: " + status);
$('#post-result').append(data);
});
});
});
</script>
<form action="result.php" id="searchForm">
<input type="text" name="name" placeholder="Search..." />
<input type="submit" value="Search" />
</form>
<div id='post-result'></div>
最後一個問題。我在上面的代碼中添加了一個簡單的表單。我只是改名:「邁克」到term = $ form.find('input [name =「name」]').val(),?再次感謝! –