Within the context of this exercise, in the section where you read: “If you want to challenge yourself:”, you are encouraged to use a different API to make a GET or POST request. What other API’s are there and what are they? I’m not very clear on this.
And when I played around a bit and tried to use the property responseText just before it, e.g. alert('Response text = ', xhr.responseText), all I got was “Response text =”.
The exercise uses something I don’t see in the specs and when I use something from the specs, I don’t get my expected result. I must be misunderstanding something. Any suggestions on what I’m missing?
You may have figured this out already, but w3schools.com is not an authoritative source and may have incomplete information or even be wrong. In the case of XMLHttpRequest, the documentation is at developer.mozilla.org
does anyone know of someplace else that has a better tutorial on the topic of this whole module? I just got done with this module and feel like i understand anything
Literally the worst lesson on this site. No explanation, no depth, no application, just copy and paste this code here with a congrats!! you did it after
I am trying to replicate the wordsmith project, and learning about each block of code and how it relates to the AJAX request.
in the main.js file, I can’t understand why we need this function:
event.preventDefault();
I understand the code below:
while(responseField.firstChild) // while we there is a child HTML element in the response field
responseField.removeChild(ResponseField.firstChild); //remove the element to refresh
However, I have no idea why we need ‘preventDefault’ for it to work. I can’t get it to load the response to the div on my own without that key piece of code.
Is there some default button action with the event listener that we have to clear out? I though the whole point is we assign the function to the event listener.
For example, the built in behavior of Submit in a form element is to build an array of name/value pairs and send to the server address in the action attribute. Our script cannot run if this default behavior is not disabled.