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>)
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.
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.
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+
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 !
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 !
This might be a bug, may be worth to file a bug report to tracker.