Using jquery I do this:
$(function() {
$('#iButton').change(function() {
$.ajax({
url: 'index.php?option=com_cameras&task=globalmotiondetection&id_hash=<?php echo $id_hash; ?>&global_monitoring='+ (this.checked ? 1 : 0) + '&format=raw'
});
});
});
This works great. But now I’m putting this into a php function (Joomla coding) but can’t figure out the quotes:
$doc->addScriptDeclaration('
$(function() {
$("#iButton").change(function() {
$.ajax({
url: "index.php?option=com_cameras&task=globalmotiondetection&id_hash='$id_hash'&global_monitoring="+ (this.checked ? 1 : 0) + "&format=raw"
});
});
});
');
This gives me: Parse error: syntax error, unexpected T_VARIABLE on the url line. Not sure how the quotes should look like. I guess I can’t just put $id_hash in there either (I’m guessing because of the error). Any ideas?
To concatenate a variable into single-quoted string, you can use the concatenate operator
.:Alternatively, you can use a double-quoted string instead, which allows you to interpolate the variable right inside: