我尝试点击它按钮搜索,路由器页面搜索和搜索数据在PHP中。这是我的代码
HTML:
<input type="text" placeholder="Search" ng-model="vm.search">
<button ui-sref="search?({item : vm.search})" class="btn btn-default"></button>
路由器
.state('search?',{
url:'/search?/{item}',
templateUrl:'/saha/src/client/app/search/search.html',
controller:'searchController',
controllerAs:'vm',
resolve:{
searchItems : ['dataServices','$stateParams',function(dataServices,$stateParams) {
return dataServices.searchItem($stateParams.item)
}]
}
})
控制器
function searchController(logger,$stateParams,searchItems) {
var vm = this;
vm.data = searchItems;
console.log(vm.data);
}
服务
function searchItem(item) {
return $http({
method:'GET',
url: 'searchItem.php?item=' + item,
data : {
item: item
},
headers:{'Content-Type':'application/x-www-form-urlencoded'}
}).then(function(data) {
return data.data;
})
}
和php
$row= array();
$item = isset($_GET['item']) ? trim($_GET['item']):'';
$sql = "SELECT * FROM item WHERE tensp LIKE CONCAT('%',?,'%')";
if($stmt= $conn->prepare($sql)){
$stmt->bind_param("s",$item);
$stmt->execute();
$result = $stmt->get_result();
while($r = $result->fetch_array(MYSQLI_NUM)){
$row[] =$r;
}
}
echo json_encode($row);