I am new to using Session variables and have been struggling despite scouring the net to understand.
So basically I have a page (search.php). I load a dynamic data table based on a search form. Once the table is loaded, via AJAX I perform the following:
$.ajax({
type:'POST',
url:'/ITSMIS/data/asset/search.php',
data:HardwareAsset,
dataType: 'html',
// When PHP / SQL Query Has Been Executed If Data Is Returned
success:function(data){
// Load The Data Table Results
LoadDataTable(data);
// Generate Hyperlinks For The Table Rows
$('#data-table tr').click(function(){
var HyperlinkHardwareAssetID = $(this).data('id');
$.ajax({
type:'POST',
url:'/ITSMIS/session.php',
data: HyperlinkHardwareAssetID,
success: function(data){
alert("great!");
}
});
window.location = $(this).data('href');
});
}
})
As you can see on Success and on click of a table row record, the idea is I post a variable via AJAX to use later. And redirect the user to the update.php page.
I am expecting to then create a session variable in the session.php page using the POSTED AJAX variable.
session_start();
$_SESSION["HardwareAssetID"] = $_POST["HyperlinkHardwareAssetID"];
I am then expected when the update.php page loads to display the Session variable result on the page.
$session = $_SERVER['DOCUMENT_ROOT'];
$session .= "/ITSMIS/session.php";
include_once($session);
echo $_SESSION["HardwareAssetID"];
But I only get the following error:
Notice: Undefined index: HyperlinkHardwareAssetID in C:\xampp\htdocs\ITSMIS\session.php on line 3
Implying for some reason the AJAX POST on click of the table row hasnt worked. However the alert with the success is always triggered.
Any ideas???