我对 AJAX / jQuery 还很陌生,我只是在探索这是我的问题我有一个文本框,我想要做的是如果我单击搜索按钮,搜索结果将加载(#sort-results)我不知道这有什么问题..我希望有人能让我理解更多。谢谢。
索引.php
<input type="text" name="item_type" class="item_type"></td>
<select class="location">
<option value="bldg1">bldg1</option>
<option value="bldg2">bldg2</option>
</select>
<button class="btn_search">Search</button>
<div id="sort-results"></div>
脚本.js
$(".btn_search").click(function(){
type = $(".item_type").val();
location = $(".location").val();
if(type.length > 0){
$.ajax({
type: "GET",
url: "sort.php",
data: "type="+type +"location="+location,
cache:false,
success : function(){
$("#sort-results").html();
}
});
}
});
排序.php
require 'global/db.php';
require_once 'config.php';
$type = $_GET['type'];
$location = $_GET['location'];
$db = new Database(DBHOST, DBUSER, DBPASS, DB);
$selection = $db->select("SELECT * FROM os_inventory WHERE os_type like '$type' AND os_location like '$location'");
echo "<table class=bordered>
<tr><th>Item</th>
<th>Item Code</th>
<th>Item Type</th>
<th>Serial No.</th>
<th>Date Added</th>
</tr>";
foreach ($selection as $key) {
echo "<tr>";
echo "<td>" . $key['os_id'] . "</td>";
echo "<td>" . $key['os_type'] . "</td>";
echo "<td>" . $key['os_code'] . "</td>";
echo "<td>" . $key['os_serial'] . "</td>";
echo "<td>" . $key['os_date'] . "</td>";
echo "</tr>";
}
echo "</table>";