我有一個表單,如果用戶輸入搜索查詢,它的參數應該通過jquery傳遞,獲得結果後它應該將結果加載到div容器中。因爲我對jquery不太熟悉,我會如何做到這一點?通過jquery傳遞搜索參數
HTML:
//currently the data is being displayed on pageload:
$(document).ready(function() {
$("#bquote").load("quotes_in.php")
});
$(".bsearch")
.keydown(function() {
//pass the parameter to the php page
//display in div #bquote
});
<!-- Begin Search -->
<div id="search" style="display:none;">
<input type="text" class="bsearch" name="search" value="Search" />
</div>
<!-- End Search -->
PHP [使用OOP]:
if (isset($_POST["search"]))
{
$quotes->searchQuotes();
}
PHP類:
$search = $_POST['search'];
$sql = "SELECT * FROM thquotes WHERE cQuotes LIKE '%"
. mysql_real_escape_string($search) ."%' ORDER BY idQuotes DESC";
try {
$query = $this->_db->prepare($sql);
$query->execute();
if(!$query->rowCount()==0)
{
while($row = $query->fetch())
{
echo $this->formatSearch($row);
}
謝謝,這有效,但如果我想在#bquote容器中顯示結果呢?另外,由於它正在獲取數據,因此沒有跡象表明它在後臺獲取數據。我會在哪裏顯示loadeR? – input 2010-07-27 00:41:36
你現在已經在回答所有問題了:)檢查編輯好的零件... – KakambaWeb 2010-07-27 00:51:11
謝謝!公認。 :) – input 2010-07-27 01:07:31