Skip to content Skip to sidebar Skip to footer

Javascript Basic Syntax Error

There's some syntax error in following jQuery code line. Its in the php part where i'm trying to assign the php session value to COMMENT_ID. 'scriptData': {'COMMENT_ID': '

Solution 1:

Consider using PHP's JSON generator to create the data structure instead of building it by hand:

<scriptlanguage="text/javascript">var foo = <?phpecho json_encode(array(
        'scriptData' => array(
            'COMMENT_ID' => $_SESSION['COMMENT_ID']
        )
    ));
?>;
</script>

Solution 2:

Are you sure your PHP code is being executed? Those single quotes, if not parsed will cause the syntax error...

If so, what is the PHP code injecting into your page? Perhaps you should provide us with the rendered script?

Post a Comment for "Javascript Basic Syntax Error"