Turbo19973 Turbo19973 - 4 months ago 10x
Ajax Question

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');
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;


If i understand well this test your doing...
Your JavaScript rowid is the value. The $_POST identifier is id.

Try this in your PHP:

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

You'll get the javascript rowid sent as a POST value (named as $_POST['id']) via ajax...
And returning in data on ajax success.


So you'll have to use data in your jQuery html()... Wich is the echoed text.