0

In my php file 'login_success.php', I have a the variable $_COOKIE["user"]

Would it be possible to return that variable within a jQuery Ajax statment such as this one. ive made a guess with Var UserName =:

function StartAjax(NameID){
    $.ajax({
      type: "POST",
      url: "login_success.php",
      cache: false,
      data: "name=Peter&location=Sheffield",
      success: function(html, status){
        $("#"+NameID).append(html);
        //$('#status').append(status);
        var userName = 

      } 
    });

1 Answer 1

1
login_success.php:
echo $_COOKIE['user'];

Ajax asks for the page, returns the output/content (what is echoed). Please note: Javascript is client side. PHP is server side. So you can't directly access PHP variables, but as done above, PHP can "give" the client the info it needs. If you're sending a lot of data, you can json_encode it for the ajax request. (you can learn about JSON on your own)

Also note, Javascript can access cookies, but I'm assuming this is just a sample question.

Sign up to request clarification or add additional context in comments.

1 Comment

That's sound advice and i've managed to extract the data what I need using that method. Thanks mate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.