2

I have a jQuery function named Update.

If $_SESSSION['Name'] is set, then the Update function of jQuery should be executed.

How can I do that?

2 Answers 2

3

Place a check for this in PHP, and if it is set, then print the code to the page to execute the JS function.

<?php

if(isset($_SESSION['Name'])){
    //execute the JavaScript/jQuery Update function
    ?>
    <script>
       Update();
    </script>
    <?php
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Note that this must be after the script tag that loads jQuery.
2

jQuery is a frontend technology, whereas PHP (and therefore $_SESSION) are backend technologies. Because of this, jQuery cannot directly access the $_SESSION variable.

You could create a PHP file to check for the existence of the session variable, though, and use an AJAX call to retrieve that information from the frontend.

Comments

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.