Has anyone solved the issue of the API not displaying results when I I type a word and click the “Submit” button? I have followed all instructions and I have received a check for all of them.
Please help.
I made 2 errors the tests didn’t catch so the program didn’t work. I figured out why they didn’t work by going to the next exercise and comparing my code.
The things I did wrong that the tests didn’t catch:
FIRST THING TESTS DIDNT CATCH:
for > 5. You can now start on the XMLHttpRequest object.
Declare a const named xhr and use the new operator to
create the XMLHttpRequest object.
I put const xhr = new XMLHttpRequest
I SHOULD have put const xhr = new XMLHttpRequest()
SECOND THING TESTS DIDN’T CATCH
for …
Below the anonymous arrow function you just created
(but still inside of getSuggestions()), call the .open()
method on the XHR object and pass it ‘GET’ and endpoint
as respective arguments.
I put those lines within the last curly brace of the xhr.onreadystatechange function by accident instead of below the function. The tests passed my code there too (but should not have).
I was wondering just the same thing, there is no export/import code. But why?
Is it maybe because all the .js files are selected in the script tags in the Html file?
Thank you!
I had troubles to pass the concatenation step, but it finally got through when I wrote it like you said (wrong way).
Once the concatenation was corrected: const endpoint = url+queryParams+wordQuery;
It worked out.
Thank you again!!!
For me, it showed my request has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. After adding chrome extension named " Allow-Control-Allow-Origin: *", it fixed.
Just to list the mistake I made ( I don’t think it’s listed here) that got me to the end of the exercise but without the functionality to actually make the request and display the response:
I called .open on the end of the xhr.onreadystatechange event handler function instead of on the xhr object itself.
That is, the row underneath the handler was .open(‘GET’, endpoint)
where it should have been xhr.open(‘GET’, endpoint)
For whatever reason, codecademy seems to be missing a lot of bugs that prevent your code from running correctly. Chances are that there is something wrong with your code that didn’t throw an error and that Codecademy didn’t catch.
For me, I put the ‘open’ and ‘send’ inside the anonymous function assigned to the ‘onreadystatechange’ event handler. These belonged outside that function but still inside the getSuggestions functions.
But judging from the comments above, there are other errors from other users that codecademy apparently missed… so just double check your code.
So this must work just in the Codecademy environment because it doesn’t actually work like this in real life. IRL, you have to somehow call the function in.
How can I tie the helper function in with the main.js file outside of the codecademy environment? Trying to recreate what I learned in this lesson IRL and both scripts are running, but not listening to each other.