Demo and full code is like this : https://jsfiddle.net/xzxrp7nn/9/
My HTML code is like this :
<button type="button">Click Me</button> <div id="tes"></div> <!-- Modal Currency--> <div class="modal fade" id="priceModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> </div> <div class="modal-body"> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> My Javascript code is like this :
$(document).ready(function(){ $("button").click(function(){ $.ajax({ //type: 'POST', //url: 'script.php', success: function(data) { var priceModal = '{"attributes":{"Code":"DBL","Total":"200000"},"DayPrice":{"Date":"2016-05-26","Rate":"200000"}}'; var isitable = '<button class="btn blue tes_button" data-toggle="modal" data-target="#priceModal" id="priceModal='+priceModal+'">Test get parameter json array</button>'; $("#tes").html(isitable); } }); }); $('#priceModal').on('show.bs.modal', function(e) { //console.log('yes'); var param = e.relatedTarget.id; // var hotel_code = $(this).data('id'); console.log(param); // console.log(hotel_code); }) }); When click button "Click me", It will display button "Test get parameter json array".
When click button "Test get parameter json array", I want send parameter priceModal to modal. Parameter priceModal contain json array. I do console.log(param); in $('#priceModal').on('show.bs.modal', function(e) {.
But the result : priceModal={. It failed to get the value of priceModal
Any solution to solve my problem?
Thank you
id="priceModal='+priceModal+'"? do you mean to add your json to your element's id like that?data-price-modal="+priceModal+'"would be far more appropiratepriceModalvalue in model??