Syntax Error - unexpected token

Syntax Error - unexpected token

by Jack Williams Dodd -
Number of replies: 19

Hello,

I have just installed the latest version of Moodle (3.3+) on a local development server. All appears to have installed successfully but I am getting a Syntax Error popup on every page - see screenshot attached. I can close the window and use the page as normal after this but it is obviously far from ideal and I would like to get rid of it asap! Here are the full details of the error:

SyntaxError: Unexpected token < in JSON at position 0
    at parse (<anonymous>)
    at Nb (http://moodle.dev/lib/javascript.php/1498829509/lib/jquery/jquery-3.1.0.min.js:1:74037)
    at A (http://moodle.dev/lib/javascript.php/1498829509/lib/jquery/jquery-3.1.0.min.js:1:77562)
    at XMLHttpRequest.<anonymous> (http://moodle.dev/lib/javascript.php/1498829509/lib/jquery/jquery-3.1.0.min.js:1:80166)


Is anyone able to help please?

Attachment moodle-error.jpg
Average of ratings: -
In reply to Jack Williams Dodd

Re: Syntax Error - unexpected token

by Jack Williams Dodd -

Has anyone else experienced this issue with a fresh install of Moodle or have any idea what might be causing it?

Thanks in advance.

In reply to Jack Williams Dodd

Re: Syntax Error - unexpected token

by Rahul Rai -

Hi Jack

I search  and find answer, maybe it is helpful for you.

https://moodle.org/mod/forum/discuss.php?d=279693 

In reply to Rahul Rai

Re: Syntax Error - unexpected token

by Christopher John -

I am experiencing the same problem and I did not find the answer in this link.

In reply to Rahul Rai

Re: Syntax Error - unexpected token

by Jack Williams Dodd -

Hi Rahul,

Thank you for your response, however this did not solve my issue either. Does anyone else have any suggestions?

Many thanks

In reply to Jack Williams Dodd

Re: Syntax Error - unexpected token

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Given that we are all stuck... let's check some basics. Switch on Debugging, reproduce the error, check your web server's error log. 

Also open your browser's Javascript Console and check for javascript errors. 

My guess is that the JSON generated is getting polluted by an error of some sort. We need to track down the error.

In reply to Howard Miller

Re: Syntax Error - unexpected token

by Jack Williams Dodd -

Thank you for your response.

I have debugging switched on. 

In the error log I'm seeing these three lines repeatedly:

[Thu Jul 06 08:02:15.369344 2017] [:error] [pid 14061] [client 192.168.33.1:50831] PHP Warning:  session_start(): Cannot send session cache limiter - headers already sent in /var/www/moodle/lib/classes/session/handler.php on line 42, referer: http://moodle.dev/admin/roles/override.$
[Thu Jul 06 08:02:15.508201 2017] [:error] [pid 14254] [client 192.168.33.1:50833] PHP Warning:  session_start(): Cannot send session cache limiter - headers already sent in /var/www/moodle/lib/classes/session/handler.php on line 42, referer: http://moodle.dev/admin/roles/override.$
>[Thu Jul 06 08:02:15.711981 2017] [:error] [pid 14064] [client 192.168.33.1:50828] PHP Warning:  session_start(): Cannot send session cache limiter - headers already sent in /var/www/moodle/lib/classes/session/handler.php on line 42, referer: http://moodle.dev/admin/roles/override.$

The console is showing this:

jquery-3.1.0.min.js:1 jQuery.Deferred exception: Unexpected token < in JSON at position 0 SyntaxError: Unexpected token < in JSON at position 0
    at parse (<anonymous>)
    at Nb (http://moodle.dev/lib/javascript.php/1498829509/lib/jquery/jquery-3.1.0.min.js:1:74037)
    at A (http://moodle.dev/lib/javascript.php/1498829509/lib/jquery/jquery-3.1.0.min.js:1:77562)
    at XMLHttpRequest.<anonymous> (http://moodle.dev/lib/javascript.php/1498829509/lib/jquery/jquery-3.1.0.min.js:1:80166) undefined
r.Deferred.exceptionHook@jquery-3.1.0.min.js:1
In reply to Jack Williams Dodd

Re: Syntax Error - unexpected token

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Are you *absolutely sure*... 

1. that you have not modified the Moodle code in any way or added any custom plugins or other items - even if you think you returned it to the original

2. that you got Moodle from here (moodle.org) and not from some random source, or one-click installer, or similar.

Please also carefully check your config.php file. Is it possible that you have added white space before the initial <?php?

This error implies that some data is being sent to the client before session_start() is called. This can't really happen with core Moodle, unless something has been changed or the config.php file edited incorrectly. 

The referrer URL in the logs also looks odd to me. Do the lines really end with that $ rather than a proper url (that should, at least, end .php)?

In reply to Howard Miller

Re: Syntax Error - unexpected token

by Jack Williams Dodd -
Hi Howard,

Thanks for coming back to me.

In answer to your first two questions - yes I downloaded moodle from moodle.org and no I haven't modified the moodle code in any way.

There's no white space before the opening php tag in the config.php

Sorry, the lines in the log file were being truncated - I should have noticed this. The full referrer url at the end of each line is: http://moodle.dev/admin/search.php

I appreciate you looking at this for me!


In reply to Jack Williams Dodd

Ynt: Re: Syntax Error - unexpected token

by Gökhan BASUT -


I also met with this mistake and did not solve it. Can you reach the solution? Please help me because the method I did not try was not there.

In reply to Gökhan BASUT

Re: Ynt: Re: Syntax Error - unexpected token

by Jack Williams Dodd -

No I did not reach a solution unfortunately. I'm having to put up with it in my dev site and hope that when I move to production to error goes away!

In reply to Jack Williams Dodd

Re: Ynt: Re: Syntax Error - unexpected token

by Nikola Antonić -

Hi, I have same issue.

Is there any update with this?


In reply to Nikola Antonić

Re: Ynt: Re: Syntax Error - unexpected token

by Jack Williams Dodd -

Hello,

I'm afraid I haven't got any further with this. I will be installing moodle again on a different server soon, so hopefully this issue will go away. If I work out what the problem is in the process I'll let you know.

In the meantime if anyone else has any suggestions it would be greatly appreciated.

In reply to Jack Williams Dodd

Re: Ynt: Re: Syntax Error - unexpected token

by Nikola Antonić -

I just found a solution that works for me. 

I am not a developer, I use Moodle as a teacher and I don't know if I will explain it well, but in the settings of my hosting client (I use Awardspace hosting), I found "PHP settings" and in the php.ini file I disable "display_errors".

The error is no longer displayed smile It's clear to me that I haven't fixed the core of the problem, but it works properly for now.

I had the same problem as you, with same full details of the error. I used page normally but pop-up appeared constantly. Now when I disabled this in PHP setting I get rid of the pop-up.

Average of ratings: Useful (1)
In reply to Nikola Antonić

Re: Ynt: Re: Syntax Error - unexpected token

by Jack Williams Dodd -

Thank you for your response. Where did you find your php.ini file? I can see the setting is currently 'on' in the php info page, but I don't know how to change it.

In reply to Jack Williams Dodd

Re: Ynt: Re: Syntax Error - unexpected token

by Nikola Antonić -

I found in Control panel of my hosting client:



Then I changed in php.ini file:



I came to this because I saw this message on Moodle:

"Enabling the PHP setting display_errors is not recommended on production sites because some error messages may reveal sensitive information about your server."

Maybe you can find more information in this thread, they suggest to check congif.php file, but I didn't find anything similar in my config.php, so I check the PHP settings option in Awardspace control panel and find "display_errors" option.



Average of ratings: Useful (1)