gpt4 book ai didi

php - 在 laravel 或 Php 的搜索字段中显示 Json

转载 作者:可可西里 更新时间:2023-11-01 13:31:26 24 4
gpt4 key购买 nike

我需要在搜索栏上显示搜索到的值。

我的 Controller 代码:

$q = Input::get('q');
$query = Jobs::select('job_title')->Where('job_title', 'LIKE', '%'.$q.'%')->get();
return response()->json($query);

我的 jquery axios 代码:

 $(document).ready(function(){
$("#jobsearch").keyup(function(){
url = "{{route('searchexistingjob')}}";
var word = $("#jobsearch").val();
const data = {
'q' : word
}
axios.post(url,data).then(response =>{
for(i=0; i<response.data.length; i++){
// $('#jobsearch').val(response.data[i].value);
});
});
});

HTML代码

<input type="text" id="txtjobsearch" name="txtjobsearch" class="form-control" placeholder="Job title, designation, description..." autocomplete="off" data-id="1">

所有的东西都是正确的,但我需要如何在搜索框中显示该值有什么想法吗?

最佳答案

如果你能改变响应格式

$q = Input::get('q');
$query = Jobs::select('job_title')->Where('job_title', 'LIKE', '%'.$q.'%')->get();
return response()->json([
search_terms => $q,
results => $query,
]);

或者当您使用 ajax 时,您已经有了搜索词:

所以代替:

$('#jobsearch').val(response.data[i].value);  

您将使用:

$('#jobsearch').val(word);  

或者只是删除该行并保留已键入的内容。

关于php - 在 laravel 或 Php 的搜索字段中显示 Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47886661/

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