Php 无法在Jquery/Ajax中调用Laravel路由
我无法在laravel文件夹外调用laravel route 我的路线Php 无法在Jquery/Ajax中调用Laravel路由,php,jquery,ajax,laravel,laravel-5,Php,Jquery,Ajax,Laravel,Laravel 5,我无法在laravel文件夹外调用laravel route 我的路线 Route::resource('tmrate','WebServiceController'); 我的控制器用于获取和发布 public function store(Request $request) { Teamrating::create($request->all()); return response()->json(['response'=>'true','me
Route::resource('tmrate','WebServiceController');
我的控制器用于获取和发布
public function store(Request $request)
{
Teamrating::create($request->all());
return response()->json(['response'=>'true','message'=>'Rating Submitted','code'=>201],201);
}
public function show($id)
{
$teamratings=Teamrating::find($id);
return response()->json(['response'=>'true','message'=>'ratings found','data'=>$teamratings,'code'=>201],201);
}
当使用邮递员点击laravel routes/url时,效果很好
http://localhost/saniservices/public/tmrate/10 for get
http://localhost/saniservices/public/tmrate?requestid=2&clientid=1&propertyid=1&servicesheetId=1&serviceTypeId=1&serviceDate=2017-05-05&rating=5&reason=Best service&comment=Great services and workd&teamId=1 for post
现在我正在使用这个代码
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<body>
<form action="#" method="post" id="idForm">
<input type="submit" value="Submit" id="submit">
</form>
</body>
<script type="text/javascript">
$("#idForm").submit(function(){
$.ajax({
url: 'http://localhost/saniservices/public/tmrate',
type: 'GET',
dataType: 'json',
data:{"id":1},
success: function (data) {
alert('success');
}
});
});
</script>
</html>
$(“#idForm”).submit(函数(){
$.ajax({
网址:'http://localhost/saniservices/public/tmrate',
键入:“GET”,
数据类型:“json”,
数据:{“id”:1},
成功:功能(数据){
警惕(“成功”);
}
});
});
但在这里我并没有从api得到任何回应,我不知道为什么会这样,我已经尝试了很多,但我并没有得到任何回应
上述文件位于laravel安装之外。问题在于,在
ajax
中,指定的类型是:
type: 'GET',
在route.php中,路由是:
Route::resource('tmrate','WebServiceController');
这里的类型是resource
。将其更改为get
并重试。问题是,在ajax
中,指定的类型是:
type: 'GET',
在route.php中,路由是:
Route::resource('tmrate','WebServiceController');
这里的类型是resource
。将其更改为get
,然后重试。您的浏览器开发工具是否显示请求?反应如何?请求URL的参数是否正确?按方法类型POST提交表单。现在控制器需要它,但您仍然通过GET调用。您的浏览器开发工具是否显示正在发出的请求?反应如何?请求URL的参数是否正确?按方法类型POST提交表单。现在控制器期待它,但你仍然打电话给GET。谢谢,我只是瞎了眼,因为它是如此简单和明显。谢谢,我只是瞎了眼,因为它是如此简单和明显。