I have the following javascript:
$(document).ready(function() {
alert('hi');
alert(<?php echo($_GET['ID'])?>);
});
When I have a url like url/?ID=222 everything works as I’d expect. When ID has a non-integer in it, url/?ID=222ff, the program crashes(no alerts)..What is going on here?
You should always wrap the value in quotes if you’re not sure of the data type:
Note, the value returned from
echoshouldn’t contain unescaped quotes, otherwise it would raise a syntax error.