0

I am getting the error "Uncaught SyntaxError: Unexpected token }" on index.php (line: 30) when i try and run certain functions of my web app (while other functions seem to work fine).

I've slightly narrowed down the problem. The error seems to occur at the "<?php" opening tag (I found this because adding a line after this tag doesn't change the line the error is given for, but an extra line before the tag and the error is given for line: 31). I've put the code in note-pad++ to check for hidden characters, I couldn't find anything out of place. Dreamweaver gives no syntax errors...

I've also looked at my AJAX JS functions (which are in a separate file). No syntax errors there, no out of place characters either.

QUESTION: Can anyone see or explain what is causing this error?

I'll place the code surrounding "line: 30" where the error is meant to be. The full code is here on github (to large to post all code here):

https://github.com/bcdawber/URL-Vault-Web-Application

CODE:

    </head>

    <body onLoad="showUrl('All URLs')">

    //console suggests error is somewhere here?
    <?php

        session_start();

        if(isset($_SESSION['userid'])) {

            echo '<div class="container">';
                echo '<div class="panel" id="backgroundPanel">';

                    echo '<div class="row">';
                        echo '<div class="large-12 columns">';
                            echo '<div class="panel">';
                                echo '<p><h2 id="title">URL VAULT</h2>';
                                echo '<h4 id="title">A Web Application for Storing URLs to Online Media.</h4></p>';
                            echo '</div>'; // <!-- END PANEL --> 
                        echo '</div>'; // <!-- END COLUMN (12) --> 
                    echo '</div>'; // <!-- END ROW -->
...........
Paul Dessert
  • 6,363
  • 8
  • 47
  • 74
Corey
  • 327
  • 5
  • 15
  • Have you looked in your "showUrl()" function? – kirkas Nov 27 '13 at 02:00
  • I'm assuming you're closing this somewhere `if(isset($_SESSION['userid'])) {` correct? – Paul Dessert Nov 27 '13 at 02:01
  • And have you tried change "onLoad" by "onload"? – kirkas Nov 27 '13 at 02:04
  • The showUrl() function is one of the functions that working, that data appears correctly from that function/process. Yes, I have closed the if statement, as well as the else statement that follows it. onLoad has been working fine, however I tested your suggestion and no change in the error. – Corey Nov 27 '13 at 02:09

1 Answers1

1

In index.php, you have several lines like:

echo '<a href="#" class="small button radius expand" onClick="showUrl("All URLs");return false;"/>All URLs</a>';
echo '<a href="#" class="small button radius expand" onClick="showUrl("Television");return false;"/>T.V URLs</a>';
echo '<a href="#" class="small button radius expand" onClick="showUrl("Movie");return false;"/>Movie URLs</a>';
echo '<a href="#" class="small button radius expand" onClick="showUrl("Music");return false;"/>Music URLs</a>';

The parameters to showURL are double-quoted, but so is the call to showURL itself. The parameters to showURL need to have a double backslash. E.g.

onClick="showUrl(\\"All URLs\\")
Matt
  • 20,108
  • 1
  • 57
  • 70
  • Hi, I changed to the suggested code and the error changed to Uncaught SyntaxError: Unexpected token ILLEGAL. – Corey Nov 27 '13 at 03:39
  • Seems like a different error. Maybe this might help: http://stackoverflow.com/questions/12719859/syntaxerror-unexpected-token-illegal If that doesn't, then this might be a good opportunity to get familiar with a JavaScript debugger. For example, the built-in debugger in Chrome. If you open the console, it can often help locate these kinds of javascript errors with line numbers and a stack trace. If you don't know what these mean, then you can always start a new SO question with the output from the debugger. You may have to do a little googling on this terminology. – Matt Nov 27 '13 at 04:36