How fetch data from a mysql database using ajax (laravel)? How to update the block dynamically .message_box
AJAX
$(function () {
$.ajax({
url: "",
dataType: 'html',
success: function(responce){
$('.message_box').html(responce); // this div to be updated
}
});
});
Blade
<div class="message_box">
@foreach($message as $content)
{{ $content->message }}
@endforeach
</div>
Controller
public function chat()
{
$message = MessageModel::orderBy('id')->get();
return view('chat.chat', ['message' => $message]);
}
Updated code