Hello,
Any idea on this comment on the bottom of page source: "<!-- 0.030654191970825 seg. -->"? I've seen it on some Osclass sites. Is it Osclass or server related? Does anyone know how to remove it? I want to parse JSON received from AJAX call but that comment gets in the way and give me an error: "Uncaught SyntaxError: Unexpected token < in JSON at position 48".
Sample response: "{"option_1":null,"option_2":null,"msg":"Already voted."}<!-- 0.0044479370117188 seg. -->".
Using JSON header (header('Content-Type: application/json');) is not helping.
PHP code:
<?php
function options_vote() {
if(Params::getParam('page') == 'options_vote' && Params::getParam('action') == 'vote') {
$response = array();
$response['option_1'] = null;
$response['option_2'] = null;
// Voting code...
// More voting code...
$response['msg'] = 'Voted successfully';
echo json_encode($response);
exit();
}
}
osc_add_hook('init', 'options_vote');
?>
JS code:
<script>
function options_vote(option) {
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var data = JSON.parse(this.responseText);
document.querySelector('.options_vote .response p').innerHTML = data.msg;
}
};
xhttp.open('GET', '<?php echo osc_base_url(1); ?>?page=options_vote&action=vote&option='+option, true);
xhttp.send();
}
</script>
Response (with/without JSON header):
{"option_1":null,"option_2":null,"msg":"Already voted."}<!-- 0.0044479370117188 seg. -->
Regards.