Parsing JSON data gives error

Parsing JSON data gives error
0

#1

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


#2

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.


#3

but the error happens with every request.


#4

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.