Finding data with angular and php

I am trying, when I click on the search button, the router on the page search and data search in php. Here is my code

HTML:

<input type="text"  placeholder="Search" ng-model="vm.search">
<button ui-sref="search?({item : vm.search})" class="btn btn-default"></button>

      

router

.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)
                                }]
                            }

                        })

      

controller

function searchController(logger,$stateParams,searchItems) {
                var vm = this;
                vm.data = searchItems;
                console.log(vm.data);

        }

      

services

 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;


})
                }

      

And 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);

      

But I am getting an empty array in the controller. Where is my mistake? please help me Here is the console I get enter image description here

+3


source to share





All Articles