如何在typeahead表单中添加csrf_token()?

我不是一个经验丰富的开发人员,所以我无法弄清楚如何在我的表单中使用ajax。 我正在尝试使用bootstrap typeahead。 但我的csrf_tokenfilter导致“500”错误。 我在哪里可以在我的ajax脚本中发送csrf_token?

 $('.typeahead').typeahead({ source : function(typeahead, query){ $.ajax({ url : 'typequery', type : 'POST', data : { query : query, column : 'title' }, dataType : 'json', async : true, success : function(data) { return process(data.titles); } }); } });  

这是我需要填写的表格。 如果我评论我的postfilter,它会工作。

 {{ Form::open(array('url' => 'searchblogs' ,'id' => "search", 'class' => "input-append")) }}     {{ Form::close() }} 

这是我的控制器

 public function postTypeahead() { $query = Input::get('query'); // Search the database. // $results = Post::select( 'title' )->where( 'title', 'LIKE', '%' . $query . '%')->take(5)->get(); $data = array(); // Loop through the results. // foreach ( $results as $result ): $data[] = $result->title; endforeach; // Return a response. // return Response::json($data); 

谢谢你的帮助。

首先,尝试调试您的ajax请求。 如果您使用的是谷歌浏览器,请打开开发工具( Top right button > Tools > Developer tools )。

打开后,导航到“ Network tab ,然后单击底部栏中的XHR 。 在这里,您将看到每个异步请求。 收到请求后,请尝试查看是否有任何错误。