Php 在laravel控制器中访问jquery数据
在我的laravel控制器中从ajax访问数据时遇到问题。 我的代码可以在本地Apache上运行,但不能在服务器nginx上运行(不知道这是否是问题所在) 如果我使用一个静态SQL请求,它可以工作,但是我需要动态地访问数据 http路由正常,但控制器中没有获取数据 我的控制器功能:Php 在laravel控制器中访问jquery数据,php,jquery,ajax,laravel,nginx,Php,Jquery,Ajax,Laravel,Nginx,在我的laravel控制器中从ajax访问数据时遇到问题。 我的代码可以在本地Apache上运行,但不能在服务器nginx上运行(不知道这是否是问题所在) 如果我使用一个静态SQL请求,它可以工作,但是我需要动态地访问数据 http路由正常,但控制器中没有获取数据 我的控制器功能: public function readHSauswahl(Request $request){ $data = Message::where('name', '=', $request->t
public function readHSauswahl(Request $request){
$data = Message::where('name', '=', $request->title)->get();
return response()->json($data);
我的路线:
Route::get('/readHSauswahl', 'AjaxController@readHSauswahl');
还有ajax调用:
$.ajax({
type: 'get',
url:'{!!URL::to('/readHSauswahl')!!}',
dataType: "json",
data:{'title':hochschule_name},
success:function(data){
console.log(data);
...
也许这与nginx配置中的
server {
listen 80;
root /var/www/html/mydata/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name http://www.mydomain.de;
location / {
try_files $uri $uri/ /index.php?query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
编辑:
按建议更改路线。仍然可以在本地工作,但不能在服务器上工作
在控制器中尝试:
$data1 = $_GET['title'];
//internal server error
$data = $request->input('title');
//same behaviour as before
最好给你的路线命名
Route::get('/readHSauswahl', 'AjaxController@readHSauswahl')->name('readhsa');
并在ajax中使用route()
helper设置url
$.ajax({
type: 'get',
url:'{{route('readhsa')}}',
});
似乎
url:'{!!url::to('/readHSauswahl')!!}',
没有生成正确的要命中的url。请尝试使用硬编码url oncethanks获取评论。但它是正确的url。在chromes网络日志中检查了它