FAQ: Requests I - XHR GET Requests III

#1

This community-built FAQ covers the “XHR GET Requests III” exercise from the lesson “Requests I”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise XHR GET Requests III

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

#2

There were no suggestions found!  This is for ```cat or bat``` very simple words? Am i doing something wrong? I got a check marl at each step.

#3

Even though I completed tasks 1 through 9, the API doesn’t display any results when I type a word and click the “Submit” button

5 Likes
#4

Why is it that in order to run the renderRawResponse function, it does not have to be imported into main.js?

2 Likes
#5

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.

#6

Ditto here. No video solution, no live chat help anymore, the last four lessons have been problem-ridden this way.

#7

POSSIBLE FIXES if your program didn’t work

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 …

  1. 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).

2 Likes
#8

Thanks for the heads up with the brackets after XMLHttpRequest - I totally forgot about them :slight_smile:

#10

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?

#11

Don’t know if you ever solved this issue, but the solution is with the concatenation step 4.

If you concatenated with a ’ ', then the api query won’t work correctly.

Basically, if you did this:

url + ’ ’ + queryParams + ’ ’ wordQuery

It won’t work because you’re adding a space between the url parameters which results in:

https://api.datamuse.com/words? rel_rhy=

This is what it should look like: https://api.datamuse.com/words?rel_rhy=

concatenating without ’ ’ will get you the correct result and make everything work.

5 Likes
#12

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!!!

#13

I would like to know where is the AJAX async function into the exercise ?! we have just anonymous normal functions.
the xhr generates async requests!?

thanks.

#14

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.

#15

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)

#16

I did everything in this lesson but after clicking Submit button nothing happends. Why?

#17

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.