Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax实时搜索文章到Laravel视图_Javascript_Php_Jquery_Laravel - Fatal编程技术网

Javascript Ajax实时搜索文章到Laravel视图

Javascript Ajax实时搜索文章到Laravel视图,javascript,php,jquery,laravel,Javascript,Php,Jquery,Laravel,我正在从一个视图创建一个实时搜索,我想知道为什么我会得到一个无响应数据,即使标题显示它在发布后发送数据。我的搜索栏位于templates/reports.blade.php中: <div class="large-6 columns"> <input type="text" id="search-input" onkeyup="searchup()" onkeydown="searchdown()" placeholder="Sea

我正在从一个视图创建一个实时搜索,我想知道为什么我会得到一个无响应数据,即使标题显示它在发布后发送数据。我的搜索栏位于templates/reports.blade.php中:

           <div class="large-6 columns">
            <input type="text" id="search-input" onkeyup="searchup()" onkeydown="searchdown()" placeholder="Search Recipient"></div>
            <div id="search-results"></div>
我的路线是:

    Route::group(['middleware' => ['web']], function () {
    Route::resource('reports', 'ReportsController');
    Route::post('reports/executeSearch', ['uses' => 'ReportsController@search']);
    });
我的控制器是这样的:

public function index()
    {
        // get all the reports
        $reports = Reports::all();

        // load the view and pass the reports
        return View::make('templates.reports')
            ->with('reports', $reports);
    }

    public function search(Request $keyword)
    {
        $searchUsers = Recipients::where("name", "iLIKE", "%{$keyword->get('keywords')}%");
        return View::make('templates.searchUsers')->with('searchUsers', $searchUsers);

    }
如您所见,它将数据发送到templates/searchUsers.blade.php,这是一个简单的循环:

@foreach($searchUsers as $key => $value)
    <b>{{ $value->name }}</b>
    <br>
@endforeach
@foreach($searchUsers as$key=>$value)
{{$value->name}

@endforeach

但由于某些原因,它似乎没有附加到我的reports.blade.php中。我只是通过js插入它吗?

我想这是因为您没有使用
get()
从查询生成器获取集合

尝试:


使用
.fail()
进行错误处理。您的请求返回时可能是非200状态。它是200 OK状态。这是什么意思?你能在开发者工具栏(chrome)或firefox中看到响应吗?在这里。。我得到了200个ok(),并且“关键字”传递得很好。我只是不确定是否可以使用单独的刀片来进行此操作。我忘了包括它。谢谢注意。:)
@foreach($searchUsers as $key => $value)
    <b>{{ $value->name }}</b>
    <br>
@endforeach
$searchUsers = Recipients::where("name", "iLIKE", "%{$keyword->get('keywords')}%")->get();