jquery自动完成和Laravel 5.1抛出内部服务器错误500

Oor看到在这里:

this is the script

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js" ></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('input:text').bind({

            });
            $("#auto").autocomplete({
                minLength:2,
                source: '{{ URL('getdata') }}'

            });
        });
    </script>

在控制器中为此:

public function getData(){

            $term = Input::get('term');

            $data = DB::table('items')->distinct()->select('item_name')->where('word', 'LIKE', $term.'%')->groupBy('word')->take(10)->get();
            foreach ($data as $v) {
                $return_array[] = array('value' => $v->word);
            }

            return Response::json($return_array);


    }
Maybe您可以发布服务器日志的条目,显示导致500服务器错误的原因? CSRF-token通常不会出现500错误CKE29
我可以找到服务器日志吗?Chriz74
你在开发什么?您使用什么软件作为服务器? Apache2在Windows上?CKE29
@ 92_egdeh MAMP在OSX上Chriz74
Your serverlogs should be around /var/log/httpd or see here: serverfault.com/questions/199462/...请看看error.log如果有的话。HECKE29

回答 2

  1. 赞同 0

    问题在GetData函数中,这是一个有效的。

    public function getData(){
    
                $term = Input::get('term');
    
                $data = DB::table('items')->distinct()->select('item_name')->where('item_name', 'LIKE', $term.'%')->groupBy('item_name')->take(10)->get();
                foreach ($data as $v) {
                    $return_array[] = array('value' => $v->item_name);
                }
    
                return Response::json($return_array);
    
    
        }
    

    Chriz74
  2. 赞同 0

    Inspector.js:44获得http://127.0.0.1:8000 /产品/自动完成?条款= D500(内部服务器错误)#*This is my Controller

    public function autosearch(Request $request){
                    // dd($request->all());
                    $query = $request->get('term','');
                    $allproducts = Product::where('product_title','LIKE','%'.$query.'%')->get();
    
                    $data = array();
                    foreach($allproducts as $product)
                    {
                        $data[] = array('value'=>$product->product_title,'id'=>$product->id);
                    }
                    if(count($data))
                    {
                        return $data;
                    }
                    else{
                        return ['value'=>"No Result Found",'id'=>''];
                    }
            }
    

    This is my script tag:

    <script>
               $(document).ready(function(){
                   var path = "{{route('autosearch')}}"
                   $('#search_text').autocomplete({
    
                       source:function(request,response)
                       {
                           $.ajax({
    
                               url:path,
                               dataType:"JSON",
                               data:{
                                   term:request.term
                               },
                               success:function(data)
                               {
                                   response(data);
                               }
    
                           });
                    
                       },
                       minLength:1,
    
                   });
               });
           </script>
    
    
    

    This is my HTML Form:

                                <div class="col d-none d-xl-block">
                                   
                                        <label class="sr-only" for="searchproduct">Search</label>
                                        <div class="input-group">
                                            <input id="search_text" type="search" name="search" class="form-control py-2 pl-5 font-size-15 border-right-0 height-40 border-width-2 rounded-left-pill border-primary typeahead"  placeholder="Search for Products" aria-label="Search for Products" aria-describedby="searchProduct1" autocomplete="off" required>
    
                                            <div class="input-group-append">
    
                                                <button class="btn btn-primary height-40 py-2 px-3 rounded-right-pill" type="submit" id="searchProduct1">
                                                    <span class="ec ec-search font-size-24"></span>
                                                </button>
                                            </div>
                                        </div>
                                    
                                </div>
    
    
    

    Mokammad Al Amin Siam