我有一个表单,如果用户输入搜索查询,它的参数应该通过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