Trying to display my message thread within a modal is proving difficult. When I click the modal button, not all messages with the same reference number are being retrieved. It seems that my code is executing the query before receiving the reference number passed to the controller. Can someone assist me in resolving this issue? Here's a snippet of my code:
This is the HomeController:
public function getAllMessage(Request $request){
$refNumber = $request->get('refNumber');
$messageThread = DB::TABLE('i_di_thread')
->SELECT('message')
->WHERE('refNumber', $refNumber);
return view ('showInquiries', ['messageThread'=>$messageThread]);
}
This is the JavaScript function:
$('#inquire_t tbody').on('click','#mensahe',function(){
var refNumber = $(this).attr('value');
getMessageThread(refNumber);
function getMessageThread(refNumber){
$.ajax({
url: 'getMessageThread',
type: 'GET',
headers: {'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')},
data: 'refNumber='+refNumber,
dataType: 'text',
success:function(msg){
}//each
});
}
And here's the blade template:
<!-- MODAL FOR MESSAGE THREAD -->
<div id="threadmessage" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Message Thread</h3>
</div>
<div class="modal-body" style="height: 300px;" >
<div class="row" style=" margin-left: 30px; margin-bottom: 5px; left: 20px; width: 550px; height: 200px; overflow: auto;">
<div>
@foreach ($messageThread as $thread)
{{$thread->message}}
<br>
@endforeach
</div>
<br>
</div>
<div>
<br>
<div class="col-md-2">
<b> Message: </b><br>
</div>
<div class="col-md-10">
<textarea required=" " id="messageContent" style="resize: none;" class="form-control" rows="2"></textarea>
</div>
</div>
<br>
</div>
<div class="modal-footer">
<div>
<button type="button" id="btn-message" class="btn btn-default" data-dismiss="modal" style="background-color: #3c5fa6; color: white;">
Send <i class="fa fa-paper-plane-o ml-1"> </i>
</button>
</div>
</div>
</div>
</div>