javascript - why y modal only show the first article id? -


how can load unique item each modal? have bootstrap modal.i've loaded details ajax modal body.but it's show first article details each article:(

how can fixed it?i've set class instead of id did not work.

html:

<button type="button" class="bmodal">article id</button> <div class="modal fade" id="mymodal" role="dialog">     <div class="modal-dialog">         <div class="modal-content">         <div class="modal-header">             <button type="button" class="close" data-dismiss="modal">&times;</button>             <h4 class="modal-title">modal header</h4>         </div>         <div class="modal-body"></div>         <div class="modal-footer">             <button type="button" class="btn btn-default" data-dismiss="modal">close</button>         </div>         </div>     </div> </div> 

javascript:

$(".bmodal").click(function () {     $.ajax({         type: 'post',         url: 'ajax.php',         data: {             publisher:a,             action: 'show'         },         success: function (data) {             $("#mymodal").modal('show');             $(".modal-body").html(data);         }     }); }); 

just give idea here is, first need assign common class button , unique id each button answere here

example:

<button type="button" class="bmodal" id="bmodal_1">article id 1</button>

<button type="button" class="bmodal" id="bmodal_2">article id 2</button>

then event bind common class , should check id has:

$(".bmodal").click(function(){    var idarray = $(this).attr('id').split('_');    //this should give array idarray [0] = 'bmodal' , idarray [1] = '1 or 2' depends button clicked.    //since you'll need number 'uniqueness' id number..   var id = idarray[1];    //then call modal has same id number, make call each modal depends button clicked.   $("#mymodal_"+id).modal('show');  }); 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -