I want show the specific record by id through on click event in model
the model is papering without any detail fetched by url function
<button id="{{$res->id}}" class="btn btn-info" data-toggle="modal" data-target="#modal-xl" onclick="viewslip(this.id)">View Slip</button>
I couldn’t get any error so I could debug this.
here i am using ajx request for getting the data by onclick function through id
function viewslip(id){
$.ajax({
url: "{{url('/view/payment/slip')}}"/+id, type: "GET", dataType:"json", success:function(data){ $('#fname').text(data.paymentslip.firstname); $('#lname').text(data.paymentslip.lastname); }
})
}
model where I am appending data <div class="table-responsive"> <table class="table"> <tr> <th style="width:50%">First Name:</th> <td><h1 id="fname"></h1></td> </tr> <tr> <th style="width:50%">last Name:</th> <td><h1 id="lname"></h1></td> </tr> <tr> Method in Controller public function viewslip($id){ $paymentslip= Order::where('reservationid', '=', $id)->firstOrFail(); return response::json(array( 'paymentslip'=>$paymentslip, )); }
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Use following code
onclick="viewslip({{$res->id}})"
And in Your function use
function viewslip($orderId){ var orderId = $orderId; $.ajax({ url:"{{url('')}}/view/payment/slip/"+orderId, // Your problem was here type: "GET", dataType:"json", success:function(data){ $('#fname').text(data.paymentslip.firstname); $('#lname').text(data.paymentslip.lastname); } })
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0