title: Including PHP variables in an external JS file?
body: <p>I have a few lines of jQuery in my web application. This code is inline at the moment because it accepts a couple of PHP variables.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $(document).ready(function(){
  
      $('.post&lt;?php echo $post-&gt;id; ?&gt;').click(function() {
  
          $.ajax({
  
              type: 'POST',
              url: 'http://domain.com/ajax/add_love',
              data: { 
                  post_id: &lt;?php echo $post-&gt;id; ?&gt;,
                  user_id: &lt;?php echo $active_user-&gt;id; ?&gt;,
                  &lt;?php echo $token; ?&gt;: '&lt;?php echo $hash; ?&gt;'
  
              },
              dataType: 'json',
              success: function(response) {
  
                  $('.post&lt;?php echo $post-&gt;id; ?&gt;').html(response.total_loves).toggleClass('loved');
  
              }
  
          });
  
          return false;
  
      });
  
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>I'm a big fan of best practices though, so I would like to move my jQuery into an external JS file.</p>
  
  <p>How could I achieve such a feat?</p>
  
  <p>Any tips? I'm still relatively new to jQuery and PHP.</p>
  
  <p>Thanks!</p>
  
  <p>:)</p>