Here is my blade view, it lists debiturs and all their properties like id, name, address. This also have a modal view button that pops a modal that is supposed to query the debitur by id then show the details of it data-target="#viewModal" onclick='showDetail({{$var->id}});
(ajax_table.blade):
<?php
if(!empty($data)){$isi = json_decode($data);}
if(!empty($modaldata)){$isimodal = json_decode($modaldata);}
?>
@if(!empty($isi->data))
@foreach($isi->data as $var)
@include('userdebitur.ajax_modal_view')
<tr>
<td>{{ $var->id }}</td>
<td>{{ $var->name }}</td>
<td>{{ $var->address }}</td>
@endif
<td>
<div class="btn-group">
<button title="Detail Info" type="button" class="btn btn-default btn-flat" data-toggle="modal" data-target="#viewModal" onclick='showDetail({{$var->id}});'><i class="fa fa-eye"></i></button>
</div>
</td>
</tr>
@endforeach
@else
<tr><td align="center" colspan="5">Not found.</td></tr>
@endif
Here is my modal file that is called from above (ajax_modal_view.blade):
<div class="modal fade" id="viewModal">
<div class="modal-dialog">
<div class="modal-content mdl-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">Default Modal</h4>
</div>
<div class="modal-body">
<p>test @if(isset($isimodal)){var_dump($isimodal)} @endif</p> //I'm trying to output this
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
The modal view button also called showDetail() passing debitur id as variable then returning data from the controller by calling a function inside ajax.blade:
function showDetail(id)
{
$.ajax({
type:"GET",
url: "{{ url('ajax/userdebitur/') }}"+"/"+id,
dataType: "json",
cache: false,
success: function(modaldata){
$("#viewModal").html(modaldata.view); //this is likely the problem
},
error: function (modaldata) {
//
}
});
}
And this is my controller:
public function getdebitur($id)
{
$content = Debitur::find($id);
$modaldata['content'] = $content;
$modaldata['view'] = view('userdebitur.ajax_modal_view')->with('modaldata', json_encode($content))->render();
echo json_encode($modaldata);
}
When using console in web browser, I have successfully retrieved the selected debitur data showing all the objects, however I can't seem to pass anything to the modal. I have tried passing the data to the ajax_table.blade itself, moving the modal inside ajax_table.blade, passing data without view from the controller, moving json_decode($modaldata) inside the modal itself, all to no avail.
If in the ajax.blade I use $("#viewModal").html(modaldata.view);
modal is showing for one second then disappear, but if I use $("#viewModal").modal(modaldata.view);
or $("#viewModal").modal(modaldata);
it's showing with no $isimodal value.
What I want to do: getting the value passed from the controller and var_dump it in the modal.