Working with the result of a $post with jQuery

Asked

Viewed 31 times

0

making a $post and getting the result json, until then everything ok, but I need to work this result outside the scope of $post(); only that the variable after the post, is empty... see the example:

    $.post(xurl, dataToBeSent, function (data, textStatus) {
        //data contains the JSON object
        //textStatus contains the status: success, error, etc
        sRetFunc = data.logado;
        console.log("JSON Data: " + data.logado);
        console.log("JSON Data: " + textStatus);
        console.log("sRetFunc =  " + sRetFunc); //<-- OK

    }, "json");

    console.log("sRetFunc after =  " + sRetFunc); //<<-- aqui fica vazio

What’s the right way to do it?

Thank you!

  • Dark Ducke, I marked your question as a duplicate of the other question because I think you’ll find the answer to your problem there. Briefly you have to put the code that needs to sRetFunc inside the callback of the $.post. If you have any doubts or think I did wrong, just say so. I’ll see you soon.

  • Another question with the same problem: http://answall.com/a/50555/129

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.