php - 在模态框搜索中显示搜索结果

标签 php jquery ajax laravel

我在模态正文中有一个搜索框。我为模态创建了一个搜索选项我也得到了结果但是在模态搜索之外工作正常但在模态搜索结果内部无法显示任何想法?

我的模态代码:

<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">&times;</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/

相关文章:

javascript - 将 JsonArray 数据从 serveResource 传递到 jsp 并在 JSP 上显示 - Liferay

php - 将多条记录从数组插入MySQL

php - 如何使用具有复杂( curl )语法的常量?

php - 是否有用于 codeigniter 的 mongodb 支持的用户身份验证库?

jquery - JQGrid - 多选

c# - MVC RedirectToAction 在 JSON 后返回后不起作用

javascript - 使用信号器更新数据库更改时如何刷新 View

php - 无法输入 ' 符号将其插入 mysql 数据库

java - 如何将列表从javascript传递到spring Controller

Javascript ajax 延迟加载和函数组织