I have
<button type="button" onclick=" showUser($_SESSION["id"] )">Change Content</button>
Is there a way to do something like
if(isset($_SESSION["id"] )) showUser($_SESSION["id"] );
?
showUser
is an AJAX script that prints something.
I want it to run without any button press.
try
<?php if(isset($_SESSION["id"] )) {?>
<script> showUser('<?php echo $_SESSION["id"];?>');</script>
<?php }?>
if (isset($_SESSION['id']))
{
echo '<script>showUser('.$_SESSION['id'].');</script>';
}
You are messing HTML, JS and PHP to one code. But yes, it's possible:
<script>
<?php
if (isset($_SESSION['id']) {
?>
showUser(<?php echo $_SESSION['id']; ?>); // do js function call to ajax function
<?php } ?>
/* rest of js */
</script>