#2
yiyanxiyin2024-06-20 09:44
|
这是控制器里的
public function getBannerImageUrl($id)
{
$banner = banner::where('id', $id)->first();
if ($banner) {
return response()->json([
'url' => asset($banner->url),
]);
} else {
return response()->json([
'success' => false,
'message' => 'Banner not found',
], 404);
}
}
这个是视图里的
###xx.blode.php
<div id="banner-container">
<img id="banner1" src="" alt="Banner Image">
</div>
<script src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var BannerId = 1; // 这里填写你想获取的Banner的ID
$.ajax({
type: "GET",
url: "{{ route('banner', ['id' => ':id']) }}".replace(':id', BannerId),
data: {// "json",
},
success: function(response) {
$("#banner1").attr("src", response.url);
},
});
});
</script>