I'm going around in frustrating circle with this one. It seems like it should be simple (probably is when you know how).
I have a button that invokes a modal that loads another page as it's content. I have the modal working if I hard-code the URL to load, but I want to pass a value (record ID) from the button to use in the URL so that the loaded page corresponds to the button, and different buttons in my page load different pages depending on that passed value.
Button code is as follows:
<button
type="button"
class="btn btn-xs btn-info"
data-target="#newModal-p"
onClick="$('#newModal-p').modal()">
<span class="glyphicon glyphicon-pencil"></span>
Edit
</button>
<!-- Modal -->
<div id="newModal-p" class="modal fade" role="dialog">
<div class="vertical-alignment-helper" style="width:50%">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title">Edit Personal Asset</h2>
</div>
<div class="modal-body">
<div id="editPage-p"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script>
var persEditPath = {!! json_encode($modal_edit_pers) !!};
$("#newModal-p").on('show.bs.modal', function () {
// load the edit form with ajax request here and place into Modal DIV
$('#editPage-p').load( persEditPath);
});
</script>
Where the $modal_edit_pers variable is "http://localhost:8080/MySite/public/admin/personal_assets/11/modal_edit"
I'd like to encode the record ID (in the path it's "11") as a value parameter when I build it in PHP so that when the button is clicked I can grab it and concatenate it into the URL string to load when I call that.
I've re-written this about five times with possible solutions I've found from searches here and elsewhere, but can't get that value all the way to the JavaScript event of the modal on(show) where I need it.
This is a Laravel 5.5 app running in XAMPP in Win10
Any and all suggestions are very welcome.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire