General developer forum

Error JSON unexpected token - Quiz

Picture of Olivier Valentin
Error JSON unexpected token - Quiz

Hi all,

I have a strange error when I delete a quiz from my Moodle 3.5.1+ (tested in 3.5.2+ too).

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

A few more information :

  • it doesn't come from my theme, I changed it to test.
  • the error occures under Firefox and Chrome. The message is slightly different, but it doesn't reaaly change anyhting.
  • the problem only occures with activities based on the question bank (for me, with the native Quiz and the Offline Qui plugin)
  • the problem only occures when the deleted quiz contains questions. If it is empty, there is no message.
  • when I close the popup message, the activity is always here. But if I refresh my page, it disappears.
I have done many searches, and the best clue for me was this forum post :
It indicates that some characters in the server response (in this case, the <br/>) aren't JSON string and apparently it made the JSON parser complain.

I tried to do the same, but I don't have the same message, and none of the characters seem to be problem.

For now... i'm stuck ! Is anyone got an idea how to resolve this problem ? Or have any other track ?

Thank you !


Average of ratings: -