0
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.

LoveAndCoding
  • 7,857
  • 2
  • 31
  • 55
rzclfy
  • 55
  • 1
  • 2
  • 7
  • The other duplicate: [Javascript - \[object Object\] means?](http://stackoverflow.com/q/8892465/1048572) – Bergi Nov 04 '14 at 16:16

4 Answers4

0

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).

letuboy
  • 1,945
  • 1
  • 11
  • 5
0

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);
mcgrailm
  • 17,469
  • 22
  • 83
  • 129
0

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

ianace
  • 1,646
  • 2
  • 17
  • 31
0

try this instead

function getAndProccessSession(){
    $.get('../session', function(returnedSessionData)
    {
        console.log(returnedSessionData);
    });
}
DMCS
  • 31,720
  • 14
  • 71
  • 104