ElJayWilson
Programmer
I am having the most difficult time getting the value of a a session variable using AJAX. I am inheriting a classic ASP application and it uses session vars to keep track of key information. I am trying to get to those values using javascript and httprequest. It doesn't work consistently though.
Here is what I got:
Here is how I am making a call to my ajax.asp script and get the data back
Here is how it gets the value (or attempts to get the value) of the session variable (named passed in as argument) (ajax.asp)
Sometimes the session variable returns nothing, other times, it returns old session variable data.
What am I doing wrong? Is there a better way to get what I need?
Here is what I got:
Here is how I am making a call to my ajax.asp script and get the data back
Code:
// This will grab the value of a server session variable and return it
function getSessionVariable(id)
{
// The server side script that will handle getting data
var ajax_url="ajax/ajax.asp?cmd=get_session_variable&variable_name=" + id
// Fire off the request and get something back
ajaxrequest.open("GET", ajax_url, false);
ajaxrequest.onreadystatechange = handlehttpresponse;
ajaxrequest.send(null);
//alert("SessionVar =" + ajaxrequest.responseText)
try
{
// Evaluate the response and create the JSON object
var returnval = eval('('+ajaxrequest.responseText+')');
return(returnval.Variable_Value); // Return the session variable value
}
catch(err)
{
return("NOVALUE");
}
}
Here is how it gets the value (or attempts to get the value) of the session variable (named passed in as argument) (ajax.asp)
Code:
case "get_session_variable"
dim variable_Name
variable_Name = Request.QueryString("variable_name")
strReturnVal = Session(variable_Name)
Set member = jsObject() ' JSON rules
member("Variable_Value") = strReturnVal
member.Flush 'Writes out (returns) the object in JSON format to the calling script
Sometimes the session variable returns nothing, other times, it returns old session variable data.
What am I doing wrong? Is there a better way to get what I need?