Unexpected token < in JSON at position 0

Unexpected token < in JSON at position 0

by John Jackson -
Number of replies: 6

Greetings,

I manage several Moodle sites. One of my clients reported that the forum digests stopped being sent a few days ago from their site, and asked me to troubleshoot. I turned on debugging and tried to send an email message to a user from within Moodle. I get the onscreen displayed error:

Unexpected token < in JSON at position 0

In searching through forum posts it seems that this and similar errors pop up in a lot of different circumstances, but usually when people have somehow changed the server configuration. We haven't changed anything, barring that the hosting company (inMotion Hosting) hasn't changed the backend configuration somehow. 

The environment is LAMP, and version of Moodle is 3.0.6. CRON seems to be running without errors. Mail server configuration looks right in Moodle, going through port 587 with password authentication. 

Any ideas would be appreciated. Thanks in advance!

John

Average of ratings: -
In reply to John Jackson

Re: Unexpected token < in JSON at position 0

by John Jackson -

I resolved my problem, which was not caused by Moodle, but by the expiration of a domain name registration. Moodle was using an email address to send messages that no longer worked. Once I set up Moodle so it was sending from an account that worked, everything was fine.

However, for the record, Moodle still displays the same error message after sending a message to an individual user, even though the message is delivered properly now. So there is some but in Moodle in this version that displays this error inappropriately.

Cheers!

John

Average of ratings: Useful (1)
In reply to John Jackson

Re: Unexpected token < in JSON at position 0

by Olaf Perlick -

Hey John,

as I am experiencing similar Problems on our Moodle Server, I would appreciate, if you could tell me, if you got further knowledge about the reasons for the behaviour. Usinf the user list, mails are sent correctly, but the syntax error still pops up. Even stranger, if I disable mail messages for online users in the message plugin settings, nothing goes wrong.


Best regards, Olaf

In reply to Olaf Perlick

Re: Unexpected token < in JSON at position 0

by Blair F. -
Picture of Particularly helpful Moodlers

We're also getting the error message, but the message still goes through.

We just upgraded from 3.2 to 3.4, which included having to change a lot of links from http: to https: and we're still finding glitches all over the place. I'm not sure if there's any connection here.

In reply to Blair F.

Re: Unexpected token < in JSON at position 0

by Blair F. -
Picture of Particularly helpful Moodlers

I'm just updating my post of August 7th, after a little more trial and error. What happens is this:

1) Send a message to someone

- SyntaxError appears

2) Close the error popup.

- The message eventually appears in the sent messages window

3) Without changing or refreshing the screen, try sending another message to the same user.

- Nothing happens - message won't send.

4) Refresh your screen, using F5

5) Try sending a message, again.

- SyntaxError appears

In other words, even though you get an error message, you can send ONE message, successfully. After that, you must refresh the screen in order to send another.

Strangely enough, and just to make matters more complicated and mysterious, shortly after I tested all of that the entire issue disappeared. But then it reappeared again, this morning! Ugh. I'm baffled.

In reply to Blair F.

Re: Unexpected token < in JSON at position 0

by Blair F. -
Picture of Particularly helpful Moodlers

Update: The problem seemed to be gone for about an hour, this morning, but then returned. How the heck do you troubleshoot something like this? Argh!

Here's what I get with debugging on:

SyntaxError: Unexpected token < in JSON at position 0
    at parse (<anonymous>)
    at Qb (https://ourmoodle.ca/lib/javascript.php/1535731337/lib/jquery/jquery-3.2.1.min.js:1:74283)
    at A (https://ourmoodle.ca/lib/javascript.php/1535731337/lib/jquery/jquery-3.2.1.min.js:1:77810)
    at XMLHttpRequest.<anonymous> (https://ourmoodle.ca/lib/javascript.php/1535731337/lib/jquery/jquery-3.2.1.min.js:1:80414)

In reply to Blair F.

Re: Unexpected token < in JSON at position 0

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Blair,
please open the Network pane of the Developer Tools and explore each request looking at its response: an AJAX call (xhr) would show you an HTML payload instead of a JSON one and in that HTML you'll read what your Moodle instance is complain about, preventing to output the expected JSON response.

Edit: are you talking here about https://moodle.org/mod/forum/discuss.php?d=374445 ?

HTH,
Matteo