我在模态正文中有一个搜索框。我为模态创建了一个搜索选项我也得到了结果但是在模态搜索之外工作正常但在模态搜索结果内部无法显示任何想法?
我的模态代码:
<div id="myModal" class="modal fade" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div id="job-title-select2" style="display:none;">
<div class="form-group">
<input type="text" id="jobsearch" name="jobsearch" class="form-control" value="" placeholder="Enter Job Title....">
<input type="submit" id="title-button" class="btn btn-info btn" value="Confirm">
</div>
</div>
</div>
</div>
</div>
</div>
jquery代码:
$("#jobsearch").autocomplete({
source: function(request, response) {
$.ajax({
url: "{{route('searchexistingjob')}}",
dataType: "json",
data: {term : request.term},
success: function(data) {
/////
}
});
},
minLength: 3,
});
控制台输出结果:
[{id: 6, value: "Analytical thinker"}]
Controller 返回值:
array (
0 => 大批 ( 'id' => 6, '值(value)'=>'分析思想家', ), )
所以我需要显示值。
最佳答案
假设你的服务器端数据是这样的
$data = array (array ( 'id' => 6, 'value' => 'Analytical thinker'));
echo json_encode($data);
在您的 ajax 成功中,将您的数据传回 ajax source
响应,如下所示。
response(data);
所以你的 ajax 代码将是,
$.ajax({
url: "{{route('searchexistingjob')}}",
dataType: "json",
data: {term : request.term},
success: function(data) {
response(data);
}
});
注意:如果一切正常但仍然无法显示肯定是 z-index
导致的问题。所以添加下面的样式并尝试,
.ui-autocomplete {
position:absolute;
cursor:default;
z-index:4000 !important
}
关于php - 在模态框搜索中显示搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47904100/