function getsession(){
var data = $.get('../session', function(data)
{
return data;
});
return data;
}
alert(getsession());
returns [object Object]
I want it to return the data from the GET.
function getsession(){
var data = $.get('../session', function(data)
{
return data;
});
return data;
}
alert(getsession());
returns [object Object]
I want it to return the data from the GET.
Since the function passed $.get
is executed asynchronously after the HTTP request is finished, you can't get a return variable.
After $("#openSession").append(data)
, you could also alert(data)
.
if you want to see the data and your using firefox maybe some others you can use
alert(getsession().toSource());
that way you can see the object that your getting back but if you know the data items you can target them direct
alert(getsession().someItemInTheObject);
if you are using google chrome you can do a console.log(getsession()) within your code and then press ctr+shift+c to open google chrome dev tools, then go to the console tab, you can see the object there and you can click it to view its internal properties values
try this instead
function getAndProccessSession(){
$.get('../session', function(returnedSessionData)
{
console.log(returnedSessionData);
});
}