【发布时间】:2020-08-07 20:16:30
【问题描述】:
我正在尝试使用 ajax 调用使用 id 获取单行项目。
路线:
Route::get('/', function () {
return view('products.categories.index');
});
Route::resource('product-categories', 'ProductCategoriesController');
Route::get('product-categories/fetchdata', 'ProductCategoriesController@fetchdata')->name('category.fetchdata');
ProductCategoriesController:
public function fetchdata(Request $request){
$id = $request->id;
$category = ProductCategory::find($id);
$data = array(
'name' => $category->name,
'subcategory' => $category->has_sub_category
);
echo json_encode($data);
}
ajaxscripts.js:
$('.edit-category-button').click(function() {
var id = $(this).attr('id');
$.ajax({
url: 'product-categories/fetchdata',
method: 'get',
data: { id: id },
dataType: 'json',
success: function(data) {
$('#editcategory').modal('show');
$('#category-name').val(data.name);
if (data.subcategory === 'Yes') {
$('#sub_cat_yes').prop('checked', true);
} else {
$('#sub_cat_no').prop('checked', true);
}
}
})
})
我收到了这个错误。
jquery.min.js:4 GET http://127.0.0.1:8000/product-categories/fetchdata?id=16500(内部服务器错误)
日志错误:
显示不存在 laravel
无法排序。我在某个地方出错了。
请让我知道任何其他信息。
请帮忙。 提前致谢!
【问题讨论】:
-
包含来自
storage/logs/laravel.log的错误日志 -
@jewishmoses 我已经添加了。我得到了解决方案。谢谢