0
爲什麼這是我的網絡控制檯中找不到此錯誤?在laravel中使用ajax 5.4錯誤:未找到
這裏是我做了什麼:
我的ajax:
function getProducts(category_id) {
$("#product-list").empty();
$.ajax({
url:'{{URL::to('home.products')}}/"+ category_id',
type:"GET",
dataType: "JSON",
success: function(data) {
}
});
}
我的路線:
Route::get('/home/products', '[email protected]')->name('home.products');
我的控制器:
public function productsbyCat($category_id)
{
$products = DB::table('products')
->select('products.product_id','products.featured_img','products.product_name','products.description',
'products.price','products.quantity')
->join('products', 'categories.category_id', '=', 'products.category_id')
->where('products.status', 'published')
->where('products.category_id', $category_id)
->get();
return $products;
}
請幫我查一下我的代碼,如果有需要改變嗎?或者我是否已經在return $products
中返回了JSON文件格式?