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.

1

4 Answers 4

0

try this instead

function getAndProccessSession(){
    $.get('../session', function(returnedSessionData)
    {
        console.log(returnedSessionData);
    });
}
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.