我是Laravel的新手。我想使用ajax方法添加产品,但在控制台POST 404 NOT FOUND
中遇到此错误。在网络中,我收到此错误消息:
{message: "", exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…}
exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException"
file: "C:\Users\rolan\Desktop\Laravel Tutorial\Fims\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php"
line: 179
message: ""
trace: [{,…}, {,…}, {,…}, {,…}, {,…},…]
这是我的Ajax代码:
<script>
$(document).ready(function(){
// alert("working");
$("#btn").click(function(){
var prodName = $("#prodName").val();
var rate = $("#rate").val();
var beginningQuantity = $("#beginningQuantity").val();
var token = $("#token").val();
$.ajax({
type: "POST",
data: "prodName=" + prodName + "&rate=" + rate + "&beginningQuantity=" + beginningQuantity + "&_token" + token,
url: "<?php echo url('/saveProduct') ?>",
success: function(data){
console.log(data);
}
});
});
});
</script>
这是179行代码</ p>
<input type="hidden" value="{{csrf_token()}}" id="token">
这是控制器代码
public function saveProduct(Request $request){
return $request;
}
这是路线
Route::get('/adminIndex',"adminIndexController@count");
Route::get('/adminInventory',"adminInventoryController@count");
答案 0 :(得分:0)
好吧,所以我不确定这是否与此有关,但似乎您可能没有在问题中正确键入它,但是您已经写了:
$.ajax({
type: "POST",
data: "prodName=" + prodName + "&rate=" + rate + "&beginningQuantity=" + beginningQuantity + "&_token" + token,
url: "<?php echo url('/saveProduct') ?>",
succes: function(data){
console.log(data);
}
});
是说success:
而不是succes:
吗?
答案 1 :(得分:0)
NotFoundHttpException通常意味着您的路由不存在。检查您的web.php文件,并确保其中存在“ / saveProduct”的路由,并且它是发布路由,而不是获取路由。
您将需要这样的路线:
Route::post('/saveProduct', 'adminInventoryController@saveProduct');