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.
<script type="text/javascript">
$(document).ready(function(){
$('.post<?php echo $post->id; ?>').click(function() {
$.ajax({
type: 'POST',
url: 'http://domain.com/ajax/add_love',
data: {
post_id: <?php echo $post->id; ?>,
user_id: <?php echo $active_user->id; ?>,
<?php echo $token; ?>: '<?php echo $hash; ?>'
},
dataType: 'json',
success: function(response) {
$('.post<?php echo $post->id; ?>').html(response.total_loves).toggleClass('loved');
}
});
return false;
});
});
</script>
I'm a big fan of best practices though, so I would like to move my jQuery into an external JS file.
How could I achieve such a feat?
Any tips? I'm still relatively new to jQuery and PHP.
Thanks!
:)