How to pass a PHP variable to ajax jquery : <p>I want to pass a PHP variable to Jquery AJAX. How can I achieve this? I tried the below script.</p>

<pre><code>$query_sess="select id from users where username='".$_SESSION['username']."'";
$result_sess = mysqli_query($con,$query_sess) or die('error');
$row_sess= mysqli_fetch_assoc($result_sess);
$userID = $row_sess['id'];
</code></pre>

<p>I need to pass this $userID to the ajax. My ajax script is as follows:</p>

<pre><code>$(document).ready(function(){

    function load_unseen_notification(view = '')
    {
     $.ajax({
      url:"fetch_notification.php",
      method:"POST",
      data:{view:view, userID: &lt;?php echo $userID; ?&gt;},
      dataType:"json",
      success:function(data)
      {
       $('.dropdown-menunot').html(data.notification);
       if(data.unseen_notification &gt; 0)
       {
        $('.count').html(data.unseen_notification);
       }
      }
     });
    }
</code></pre>
