Poornima Poornima - 25 days ago 5
jQuery Question

unable to get href Attributes using JQuery

Below is my PHP code. I am displaying 3 images, if I Click over any image or product I need to add that product in the popup modal. I am trying to get the product name but I can't. How to solve this issue.

<?php
$i = 0;
while ($row = mysql_fetch_assoc($result))
{
echo"<td style='background-color:#FFFFFF;' height='383'>
<a href='#myModal?productname={$row["productname"]} 'id='burl' role='button' data-productname='{$row["productname"]}' data-toggle='modal' data-target='#myModal'>
<img src='images/{$row["productname"]}.jpg' width='255'/>
</a>
</td>";
}
mysql_free_result($result);
?>


JQuery Codings:

$(document).ready(function () {
$('#myModal').on('shown.bs.modal', function () {
console.log($(this).data('productname'));
})
})

Answer
 $(document).ready(function ()
 {
            $('#myPopup').on('show.bs.modal', function (e) 
{
                var rowid = $(e.relatedTarget).data('productname');
                alert(rowid);
                $.ajax(
{
                    type: 'GET',
                    url: 'fetch_data.php', //Here you will fetch records
                    data: 'productname=' + rowid, //Pass $id
                    success: function (data)
 {
                        $('.fetched-data').html(data);//Show fetched data from database                      
                    }
                });
            });
        });

This coding solved my problem.
Thanks for all your reply.
Comments