mercredi 13 juillet 2016

AJAX post jQuery to PHP $_POST

I have this modal jQuery AJAX:

        $('#switch_modal').on('show.bs.modal', function (e) {
        var rowid = $(e.relatedTarget).attr('data-id');
            $.ajax({
                type : 'post', // commented for this demo
                url : 'pars.php', // commented for this demo 
                data :  'id='+ rowid,
                success : function(data) {
                $('.fetched-data').show().html(rowid); // show rowid for this demo
                }
            });
        });

My mysql query:

$query="SELECT * FROM games WHERE winner='' ORDER BY amount DESC";
while ($row = $result->fetch_assoc()) {

My modal data-id:

<a href="#viewgame" data-toggle="modal" data-id="<?php echo $row['id'];?>"">

How can i do to use the var rowid like a PHP post? Something like that:

$id = $_POST['rowid'];
echo $id;

Aucun commentaire:

Enregistrer un commentaire