So many times on this site I see people trying to do things like this :
<script type="text/javascript">
$(document).ready(function(){
$('<?php echo $divID ?>').click(funtion(){
alert('do something');
});
});
</script>
I don't think that this is some sort of pattern that people naturally fall into. There must be some sort of tutorial or learning material out there that is showing this, otherwise we wouldn't see it so much. What I'm asking is, am I making too big a deal of this or is this a really bad practice?
EDIT : Was speaking to a friend of mine about this who often puts ruby in his JavaScript and he brought up this point.
Is it ok to dynamically place application wide constants in your JavaScript so you don't have to edit two files. for example...
MYAPP.constants = <php echo json_encode($constants) ?>;
also is it OK to directly encode data you plan to use in a library
ChartLibrary.datapoints = <php echo json_encode($chartData) ?>;
or should we make an AJAX call every time?
this question will likely solicit opinion, debate, arguments, polling, or extended discussion.
...