如何使用ajax post在离子中实现此搜索查询?

时间:2022-10-07 15:39:27

如何使用ajax post在离子中实现此搜索查询?I have this search query in my codeigniter the problem is I dont know how to implement it in ionic. What I want is if I search on the searchbox in my ionic(home.html) ex. "Pepper, Oil" , the result should be the recipe that corresponds with the ingredients like adobo and kaldereta.

我在codeigniter中有这个搜索查询问题是我不知道如何在离子中实现它。我想要的是如果我在我的离子(home.html)前搜索搜索框。 “辣椒,油”,结果应该是与adobo和kaldereta等成分相对应的配方。

user_model.php ( codeigniter - model )

user_model.php(codeigniter - model)

public function get_halal($search_values)
{
    $this->db->distinct();
    $this->db->select('*');
    $this->db->from('recipe');
    $this->db->join('menu', 'menu.recipe_id = recipe.recipe_id');
    $this->db->join('ingredient', 'ingredient.ingredient_id = menu.ingredient_id');
    $this->db->where('menu.category_id = 1');

    if (strpos($search_values, ',') !== false) {
        $search = explode(',' , $search_values);
        $this->db->like('ingredient.name', trim($search[0]), 'both');
        unset($search[0]);
        foreach ($search as $term) {
            $this->db->or_like('ingredient.name', trim($term), 'both');
        }
    } else {
    //this means you only have one value 
    $this->db->like('ingredient.name',$search_values, 'both');
    }

    $query = $this->db->get();
    return $query->result();
} 

home.php ( codeigniter - controller )

home.php(codeigniter - controller)

public function ajaxSearchHalal()
{
    $postdata = file_get_contents("php://input");
    if (isset($postdata)) {
        $data = $this->user_model->get_halal($postdata);
        echo json_encode($data);
    }
}

searchService.js ( ionic )

searchService.js(离子)

return {
    all: function() {
      return $http.get('http://localhost/admin-recipick/home/ajaxSearchHalal').then(function(result){
        return result.data;
        console.log(result.data);
      });
    }

}

controller.js (ionic)

controller.js(离子)

RecipeList.all().then(function(payload) {
 $scope.recipedata = payload;

    console.log(payload);
});

 $scope.searcRecipe = function() {
    RecipeList.all();
    $state.go('app.searchRecipe');
};

home.html ( ionic - view )

home.html(离子 - 视图)

   <div class="list list-inset">
      <label class="item item-input">
          <i class="icon ion-search placeholder-icon"></i>
          <input type="text" ng-model="" placeholder="(EX. beef, fish, corn)"> 
      </label>
      <button type="button" class="button button-block button-assertive icon ion-search " ng-Click="searcRecipe()"> Search</button>
   </div>

1 个解决方案

#1


0  

RecipeList.all().then(function(payload) 
{
    console.log(payload.data);
});

use payload.data for getting response.

使用payload.data获取响应。

#1


0  

RecipeList.all().then(function(payload) 
{
    console.log(payload.data);
});

use payload.data for getting response.

使用payload.data获取响应。