I am trying to pass a PHP variable to Ajax which can then be used to return a record/data from a MySQL table.
Background I have a PHP script that returns data and displays it in rows and columns
if($Count2 < $Limit2) {
if($Coun2 == 0) {
echo "<tr>";
}
echo "
<td class='roomviewred' title='View reported fault' id='room' >
<span class='roomlinktext' >
<div class='content1'>
$RoomNo
</div>
</span>
</td>
";
} else {
$Count = 0;
echo "
</tr>
<tr>
<td class='roomviewred' title='View reported fault' id='room'>
<span class='roomlinktext'>
<div class='content1'>
$RoomNo
</div>
</span>
</td>
";
}
$Count++;
}
$RoomNo contains a string of data as a 4 digit number. what I need to do is, when either the displayed number of even the containing DIV is clicked send the data to a jquery/ajax function to send a MySQL request to the data table and return the record associated with the query string.
My jquery/ajax function
$(document).ready(function() {
var phproom = <?php echo $RoomNo;?>
new jBox('Modal', {
attach: '.roomviewred',
title: 'Reported fault',
theme: 'TooltipBorder',
closeOnClick: 'body',
ajax: {
url: 'fault_detail.php',
data: {
Room: 'phproom'
},
reload: 'strict'
}
});
}
The issue I have is when the the on screen room number is click my script is not sending the data to the ajax function. When I view this in my browser debugger I see the following:
http://www.example.com/apps/lhr/iframes/fault_detail.php?Room=phproom
what I need to see is the room number in place of "phproom":
http://www.example.com/apps/lhr/iframes/fault_detail.php?Room=0101
If I hard code the room number in the ajax call it works fine so I know I am not passing the data correctly.
Can anyone please help. Thanks in advance for your time.
'aroundphproom?$RoomNovariable as a cookie (using$_COOKIEand then accessing it using JS) or as a HTML5data-attribute of an element in the document, and then reading the value on DOM ready.phproomin console. Check if value is present or not