showing data in modal on click button not working

showing data in modal on click button not working


<!-- Main content -->
< section class = "content" >
< div class = "row" >
<!-- Left col -->
< section class = "col-lg-12 connectedSortable" >
< table class = "table table-striped table-bordered data display nowrap" style = " width:100%" id = "data" >
< thead >
< tr >
< th > Code </ th >
< th > Description </ th >
< th > Category </ th >
< th > Merk </ th >
< th > Qty </ th >
< th > Price </ th >
</ tr >
</ thead >
< tbody >
<?php foreach ( $stock as $s ) { ? >
< tr >
< td > <?php echo $s -> code ? > </ td >
< td > <?php echo $s -> description ? > </ td >
< td > <?php echo $s -> Typename ? > </ td >
< td > <?php echo $s -> merek ? > </ td >
< td class = "text-right" >
< button type = "button" id = "messageButton"
class = "btn btn-info btn-xs" data-id = " <?php echo $s -> code ; ? > " >
<?php echo number_format ( $s -> Jumlah ) ? >
</ button >
</ td >
< td class = "text-right" > <?php echo number_format ( $s -> Price ) ? > </ td >
</ tr >
<?php } ? >
</ tbody >
</ table >
</ section >
<!-- right col -->
</ div >
<!-- /.row (main row) -->

</ section >
<!-- /.content -->
</ div >

< div id = "stockModal" class = "modal fade" >
< 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" > Stock Info </ h4 >
</ div >
< div class = "modal-body" >

</ div >
</ div >
</ div >
</ div >

< script type = "text/javascript" >
jQuery ( document ). ready ( function ( $ ){
$ ( '.data' ). DataTable (
{
"pageLength" : 10 ,
"scrollX" : true
}
);
});

$ ( '#messageButton' ). on ( 'click' , function ()
{
var theMessageID = $ ( this ). attr ( "data-id" );
var theURL = '/stock/getDetail' ; //adjust according to your site/setup

$ . post ( url ,
{
MessageID: theMessageID ,
},
function ( data , status ) {
if ( status == 'success' ) {

// loop through data
$ . each ( data , function () {
$ ( '#stockModal .modal-body' ). html ( this [ 1 ]); // the actual message
});

$ ( '#stockModal' ). modal ( 'show' );

} else {
alert ( 'No message available' );
}
}
}); //end post
}
);

< / script >