Php jquery自动完成和laravel 5.1引发内部服务器错误500
我正在尝试通过从DB中选择数据并以json的形式返回响应来自动完成,但我得到的只是内部服务器错误,这可能是csrf令牌的问题吗 这是剧本Php jquery自动完成和laravel 5.1引发内部服务器错误500,php,jquery,laravel,autocomplete,Php,Jquery,Laravel,Autocomplete,我正在尝试通过从DB中选择数据并以json的形式返回响应来自动完成,但我得到的只是内部服务器错误,这可能是csrf令牌的问题吗 这是剧本 <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" ></scr
<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>
问题出在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);
}
inspector.js:44 GET 500(内部服务器错误)#
*这是我的控制器
这是我的脚本标签:
<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>
$(文档).ready(函数(){
var path=“{route('autosearch')}”
$(“#搜索_文本”)。自动完成({
来源:功能(请求、响应)
{
$.ajax({
url:path,
数据类型:“JSON”,
数据:{
期限:request.term
},
成功:功能(数据)
{
答复(数据);
}
});
},
最小长度:1,
});
});
这是我的HTML表单:
<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>
搜索
也许你可以发布一个服务器日志条目,显示500服务器错误的原因?CSRF令牌通常不会显示500错误我在哪里可以找到服务器日志?您在开发什么?您使用什么软件作为服务器?Windows上的Apache2?OSXY上的@92_egdeH MAMP您的服务器日志应该在/var/log/httpd
左右,或者请查看此处:如果有错误,请查看错误日志。
<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>
<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>