What i'm trying to do is to pass the data-id value to an external link via JQuery ajax.
The modal will show up but the data-id attribute is not sending to the external link. I think something is wrong with my Jquery script. But i can't find it.
This is my link:
<a href="javascript:;" data-id="1" onclick="showAjaxModal();" class="btn btn-primary btn-single btn-sm">Show Me</a>
This is my Jquery ajax script:
<script type="text/javascript">
function showAjaxModal()
{
var uid = $(this).data('id');
jQuery('#modal-7').modal('show', {backdrop: 'static'});
jQuery.ajax({
url: "test-modal.php?id=" + uid,
success: function(response)
{
jQuery('#modal-7 .modal-body').html(response);
}
});
}
</script>
This is my code for the modal:
<div class="modal fade" id="modal-7">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Dynamic Content</h4>
</div>
<div class="modal-body">
Content is loading...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-info">Save changes</button>
</div>
</div>
</div>
</div>
Can anyone help me out here?
I want to load the content of the page found by test-modal.
The code of test-modal.php is simple, see below:
<?php
$uid = $_GET['id'];
echo id: '. $uid;
?>
I have tried to make a jsfiddle: http://jsfiddle.net/2dp12ft8/3/ but it's totally not working.
I have changed the js code but it will still not work.
I see the modal showing up but only the word 'undefined' is showing up and not the content of the external file.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…