json - Laravel 5.1自动完成功能给Symfony fatal error

标签 json error-handling laravel-5.1 jquery-autocomplete

我仍然期待解决这个问题。简单的事情是在输入表单控件中使用自动完成功能,令我惊讶的是,它没有将记录从文本输入中输入。如果我通过浏览器查询结果,则会看到以下结果:

http://localhost:2222/json/redirects/   

我确实看到了这个结果:
[{"id":null,"value":"Andorra"},{"id":null,"value":"United Arab Emirates"},{"id":null,"value":"Afghanistan"},{"id":null,"value":"Antigua and Barbuda"},{"id":null,"value":"Anguilla"},{"id":null,"value":"Albania"},{"id":null,"value":"Armenia"},{"id":null,"value":"Netherlands Antilles"},{"id":null,"value":"Angola"},{"id":null,"value":"Antarctica"},

这是 Blade 文件:
<!DOCTYPE html>
    <html>
    <head>
        {!! Html::style('bootstrap/css/bootstrap.css') !!}
        {!! Html::style('bootstrap/css/bootstrap.min.css') !!}
        <link href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" media="all" rel="stylesheet" type="text/css" />   
        <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
        <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    </head>
    <body>
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            <section class="panel panel-default">
                <header class="panel-heading">
                    <input type="text" name="searchname" id="searchname" class="form-control" placeholder="enter name">
                </header>
                <div class="panel-body">
                    <table>
                        <tr>
                            <td><input type="text" name="id" id="id" class="form-control" placeholder="ID" ></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><input type="text" name="name" id="name" class="form-control" placeholder="Name" ></td>
                        </tr>
                    </table>
                </div>
            </section>
        </div>
    </div>
    </body>
    <script type="text/javascript">
        $('#searchname').autocomplete({
            source: '{!! Url::route('jsonRedirect') !!}',
            minlength: 1,
            autofocus: true,
            select: function(e, ui){
                alert(ui);
            }
        });
    </script>
    </html>

这是 Controller :
 public function SelectLocationPlaces(Request $userAdressRequest)
    {
        $term = $userAdressRequest->term;
        $data = Country::where('name', 'LIKE', '%'.$term.'%')->take(10)->get();
        $results = array();

        foreach ($data as $key => $value) {
            $results[] = ['id'=>$value->id, 'value'=>$value->name];
        }
        return response()->json($results);
    }

这是路线:
Route::get('json/redirects', array('as'=>'jsonRedirect', 'uses'=>'UserAddressController@SelectLocationPlaces'));

错误日志:
<body>
                    <div id="sf-resetcontent" class="sf-reset">
                <h1>Whoops, looks like something went wrong.</h1>
                                        <h2 class="block_exception clear_fix">
                            <span class="exception_counter">1/1</span>
                            <span class="exception_title"><abbr title="Symfony\Component\Debug\Exception\FatalErrorException">FatalErrorException</abbr> in <a title="C:\Users\ken4ward\Documents\xampp\htdocs\tradersmart\storage\framework\views\d12352064f8db7567c7110c110aa0321 line 39" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">d12352064f8db7567c7110c110aa0321 line 39</a>:</span>
                            <span class="exception_message">Class &#039;Url&#039; not found</span>
                        </h2>
                        <div class="block">
                            <ol class="traces list_exception">
       <li> in <a title="C:\Users\ken4ward\Documents\xampp\htdocs\tradersmart\storage\framework\views\d12352064f8db7567c7110c110aa0321 line 39" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">d12352064f8db7567c7110c110aa0321 line 39</a></li>
    </ol>
</div>

亲爱的,请问,自动完成无法正常工作但我仍可以在url上查看json响应的原因可能是什么?

最佳答案

谢谢大家。终于可以了。这是由于传递了错误的URL格式作为来源引起的。所以,我所要做的就是这样:

来自:source: '{!! Url::route('jsonRedirect') !!}',至:'{{ url('json/redirects') }}',

关于json - Laravel 5.1自动完成功能给Symfony fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34712517/

相关文章:

json - golang : Unmarshal: json: cannot unmarshal array into Go value of type main. MonitorServerInfo

javascript - React 的 Json API 访问错误

php - 网络服务器上的错误监控/处理

javascript - 为什么 JSLint 在此函数上给出严格违反错误?

c - OpenCV - C 库在我的 Ubuntu11.10 中无法工作

laravel-4 - 用户、购物车和产品的 Eloquent 关系

java - 在android中解析数据org.json.JSONException时出错

java - 使用 jackson 转换时 POJO 具有空值

javascript - Laravel 5.1 ajax 不工作?

mysql - 群组中的 UserMiddleware 问题