【发布时间】:2021-05-10 19:02:16
【问题描述】:
我正在尝试在 laravel 中使用 ajax 从数据库中获取数据。我得到了所有数据并将其成功加载到编辑表单中,除了图像。我从数据库中获取了图像,但无法在编辑表单上预览。
这是我的 ajax 调用
function editProduct(id, category_id) {
$.ajax({
url: "{{ url('admin/products/edit/') }}/" + id,
type: "GET",
contentType: false,
cache: false,
processData: false,
dataType: "json",
success: function(response) {
$("#edit-modal").modal("toggle");
$(".id").val(response.id);
$("#edit_name").val(response.name);
$("#edit_category").val(category_id);
$("#edi_image").val(); <---What to do here? --->
}
});
}
这是我的控制器代码
public function edit($id) {
$product = FoodItem::findOrFail($id);
return response()->json($product);
}
我想在这里加载图片
<img src='' id="edit_image" width="180px;" height="120" class="mt-2">
<p>Old image</p>
谁能告诉我该怎么做?
【问题讨论】:
标签: php jquery mysql ajax laravel