将ID从php传递到JS文件

I know very well that this question is ask many time but some how my problem is different and i didn't find the solution.

Now comes on issue.

I have a an image,so whenever i click on to the image the pop up window is open and show the data.now i want to make this dynamic and wants that the data should be come according to the id.

here is my image code.:

<div id='contact-form'>

        <a href='#' class='contact'><img src="<?php echo base_url();?>/assets/images/pre.jpg" style="height:18px; width:18px"></a>
      </div>
        <!-- preload the images -->
        <div style='display:none'>
            <img src='<?php echo base_url();?>assets/images/img/contact/loading.gif' alt='' />
        </div>  


And on its click the ajax is called from js file here is the code of that js file:
//here the provider is controller and show_coupon_pre is a function which call the view having the data.
$.get("provider/show_coupon_pre", function(data){
                    // create a modal dialog with the data
                    $(data).modal({
                        closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
                        position: ["15%",],
                        overlayId: 'contact-overlay',
                        containerId: 'contact-container',
                        onOpen: contact.open,
                        onShow: contact.show,
                        onClose: contact.close
                    });
                });

I have a table having no of records and each record having this type of image.where the user can click and get the preview in pop window. But i want to show the data in pop up according to the row like for id=1 it should be show the data of id==1 and so on. now can you you guys please help me how can i pass this id to the js file by which i can fetch the required data.

I am working in codeignitor.

Simplest solution

<table>
<tr>
 <td><img class="banner" src="/image1.png" post_id="1"></td>
 <td>some other data 1</td>
</tr>
<tr>
 <td>
 <td><img class="banner" src="/image1.png" post_id="2"></td>
 <td>some other data 2</td>
</tr>
</table>

Javascript:

$('.banner').click(function() { 
  post_id = $(this).attr("post_id");

  // send your ajax with post_id
} );

If you have the ID in php when outputting the image, I would do this:

<script>
var randomId = <?php echo '"' . $phpId . '"'; ?>
</script>