![](/img/trans.png)
[英]load a php query file in an html index page using ajax or jquery
[英]Search the database and load the returned query onto the page using jQuery and AJAX
我正在一個頁面上做一些工作,在該頁面上我要根據用戶的搜索內容搜索數據庫,然后在同一頁面上返回結果。 我知道如何使用jQuery使事物從頁面中消失,但是我想知道如何使用AJAX將其添加到頁面中。
我要問的簡短內容是,我想查詢數據庫,並在不重新加載頁面的情況下將結果彈出到網站上。
好吧,下面的答案並沒有真正回答我的問題,因此我將通過示例給出更詳細的問題。
<input type="textbox" id="name" name="name" />
<input type="button" id="search" name="search" value="Search the Database" /> <br/><br/>
<label class="userinfo">First Name: </label><input type="text" class="userinfo" id="first" name="first" /> <br/>
<label class="userinfo">Last Name: </label><input type="text" class="userinfo" id="last" name="last" /> <br/>
<label class="userinfo">Username: </label><input type="text" class="userinfo" id="uname" name="uname" /> <br/>
<label class="userinfo">E-Mail: </label><input type="text" class="userinfo" id="email" name="email" /> <br/>
<label class="userinfo">Admin Status: </label><input type="text" class="userinfo" id="admin" name="admin" /> <br/>
發生的是,我基於第一個文本框搜索數據庫,按下搜索按鈕時將發生AJAX,它將轉到另一頁並在數據庫上進行查詢。 如何將這些結果返回到原始頁面以填寫下面的文本框? 在單擊搜索按鈕之前,將隱藏下面的texbox。 因此,我需要發送一個變量並返回多個變量。 這對您有幫助嗎?
這是ajax + html附加的示例:
<html>
<head>
<script type="text/javascript">
$(function() {
$('.go-right').click(function(){
$.ajax({
type: "POST",
url: "process_thumbs.html",
data: "showposts=25",
success: function(html){
$("#output").html(html);
}
});
});
});
</script>
</head>
<body >
<div id="output"></div>
<a class="go-right">RIGHT</a>
</body>
</html>
當然,“ process_thumbs.html”是返回查詢結果的動態頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.