The Wikipedia Viewer that i built is working well. but when parsing the JSON data
var json = JSON.parse(requestData.responseText);
It always gives this one error
VM202:1 Uncaught SyntaxError: Unexpected end of JSON input
The Wikipedia Viewer that i built is working well. but when parsing the JSON data
var json = JSON.parse(requestData.responseText);
It always gives this one error
VM202:1 Uncaught SyntaxError: Unexpected end of JSON input
This happens when requestData.responseText
is an empty string (the status is 200).
I also get SyntaxError: JSON Parse error: Unterminated string
sometimes.
Not sure why. I haven’t done this challenge yet. It might be a feature of Wikipedia’s API.
but the error happens with every request.
I had a look at XMLHttpRequest
on MDN. I think you need to check the value of requestData.readyState
in addition to the status. If it’s not equal to XMLHttpRequest.DONE
, you haven’t got the whole data. Look at the example on MDN’s description of XMLHttpRequest.onreadystatechange.