gpt4 book ai didi

php - 如何使用 ajax post 在 ionic 中实现此搜索查询?

转载 作者:行者123 更新时间:2023-11-30 22:26:30 25 4
gpt4 key购买 nike

screencap我的 codeigniter 中有这个搜索查询,问题是我不知道如何在 ionic 中实现它。我想要的是如果我在 ionic(home.html) ex 的搜索框中搜索。 "Pepper, Oil",结果应该是与adobo和kaldereta等成分相对应的食谱。

user_model.php(codeigniter - 模型)

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 )

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 )

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 )

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

console.log(payload);
});

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

home.html( ionic View )

   <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>

最佳答案

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

使用 payload.data 获取响应。

关于php - 如何使用 ajax post 在 ionic 中实现此搜索查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35080340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com