General developer forum

Error JSON unexpected token - Quiz

 
Picture of Olivier Valentin
Error JSON unexpected token - Quiz
Particularly helpful Moodlers

Hi all,

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

SyntaxError
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 !

Olivier

 
Average of ratings: -
Picture of Konrad Lorinczi
Re: Error JSON unexpected token - Quiz
 

In my case the problem source was a missing question type.

There were existing questions with the missing question type, then later likely the question type plugin was deleted. This is why the error appeared.

Using Moodle v3.5.1+


 
Average of ratings: -
Picture of Olivier Valentin
Re: Error JSON unexpected token - Quiz
Particularly helpful Moodlers

Hi Konrad,

thanks for your answer ! It didn't helped, but I tried anyway to see if question type could be a reason.

In my case, I just migrated to Moodle 3.5.2+ last week, all my plugins are updated. When I create a test, I always create a brand new question in it, with a question type from the core (true/false generaly). But the problem is stille here : the JSON Parse Error appears as soon as I delete the test.

I tried too to create the question in different categories of the bank (related to the test, the course, the whole plateform...) : no change at all... Well, hope Moodle 3.5.3 will bring a solution ! smile

Olivier

 
Average of ratings: -
Picture of Olivier Valentin
Re: Error JSON unexpected token - Quiz
Particularly helpful Moodlers

Hi again,

based on this discussion on Moodle Forum https://moodle.org/mod/forum/discuss.php?d=352240, I searched if an invalid JSON string could be the source of the problem. And it seems yes !

Using the Network tab of the Dev tools in Firefox and Chrome, I found the message in the server response was "This category has been deleted because, after deleting the course, its questions weren't used any more", which matches with the "unusedcategorydeleted" string.

I first tried to simplify it, but it didn't help. So I tried to find where this message is called, and it comes from a function called "question_delete_context" in file questionlib.php. I put in commentary the last line returning the feedback... and now my error has disapperead !

Of course, the problem is not solved. I just blocked the feedback making parser complaining. But at least, this seems to confirm that some HTML characters are not parsed correctly when deleting question categories from the bank.

Hope this will help !

Olivier

 
Average of ratings: -
Picture of Konrad Lorinczi
Re: Error JSON unexpected token - Quiz
 

This might be a bug, may be worth to file a bug report to tracker.

 
Average of ratings: -