Hello, I am using a XMLHttpRequest to make a request to the server to get info about specific movies using a for loop. I am doing this to obtain the imdb id so that I can use another API to get the IMDb Ratings. I use a function to first retrieve all movies on the discover page, then use a for loop run a function which accesses each object in the array to set the IMDb Rating after a successful return of data from the server.
I am however getting this error:
Uncaught SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at XMLHttpRequest.movieReq.onreadystatechange (discover.js:34)
at loadIMDBDetails (discover.js:38)
at MainFunc (discover.js:71)
at discover.js:5
This is the XMLHttpRequest initialization statement:
movieReq.open('GET', 'https://api.themoviedb.org/3/movie/' + mO.id + '?api_key=<my_api_key>, false);
I am aware that this is returning data synchronously and will change that once I have fixed the issue of the unexpected end of JSON input error.
Please assist, TA
لم تجد الفلم أو المسلسل ؟ سجل دخولك و انشئها
هل تريد تقييم او اضافة هذا العنصر للقائمة؟
لست عضو؟
رد بواسطة Travis Bell
بتاريخ مارس 28, 2019 في 11:53 صباحا
Hi @MarineXII,
It's pretty hard for me to help troubleshoot this, without seeing the JSON you're trying to parse. Can you get a copy of the body that's being returned by the API when your code trips on this error?
رد بواسطة MarineXII
بتاريخ مارس 28, 2019 في 12:34 مساءا
This is the returned JSON. I found the error is caused by my missing if statement. I was missing the following if statement:
Adding this statement fixed my issue!
رد بواسطة Travis Bell
بتاريخ أبريل 3, 2019 في 2:27 مساءا
Happy to hear you sorted this out.