Saturday, 20 July 2019
Problems with creating an autocomplete searchbox using API calls
I am trying to create a little project to recommend video games to users based on their inputted game. To do this I use the IGDB API. I want to create a searchbar in the front page where it works like google's search bar: on each key press, a bunch of dropdown li's appear that autocomplete the phrase given the current string in the search bar.The problem:IGDB API limits the results to 50 a call. Therefore, I need to send a get request to the API each time a new string in the search bar is present. I use axios to send requests. The template looks like this:function myFunction(string) { return axios.get("https://api-v3.igdb.com/games", { headers: { "user-key": API-KEY, 'Accept': "application/json" }, data: 'search ' + string + '; fields name;' }).then(response =>{ console.log(response.data); }).catch(err => { console.log("Error!"); });} However, if I put this into the EJS file as a script and include axios CDN, I get this error:**Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api-v3.igdb.com/games. (Reason: CORS header 'Access-Control-Allow-Origin' missing).**Furthermore, when I use
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment