What is url in Post Data with the JavaScript XMLHttpRequest Method

JSON APIs and Ajax: Post Data with the JavaScript XMLHttpRequest Method

In the previous examples, you received data from an external resource. You can also send data to an external resource, as long as that resource supports AJAX requests and you know the URL.

JavaScript’s XMLHttpRequest method is also used to post data to a server. Here’s an example:

req=new XMLHttpRequest();
req.open(“POST”,url,true);
req.setRequestHeader(‘Content-Type’,‘text/plain’);
req.onreadystatechange=function(){
if(req.readyState==4 && req.status==200){
document.getElementsByClassName(‘message’)[0].innerHTML=req.responseText;
}
};
req.send(userName);

3 Likes

It would be the actual URL to post the data to, but in the challenge it is undefined in the example. Maybe provided by the backend if you copy the code over, however that doesn’t work. Sounds ripe for a bug report, if there isn’t one about it already.

3 Likes

I have exactly the same problem. I have tried the url which was used in the previous challenges but it does not work. Looks like a bug. Has anybody solved the problem?

I highly recommend using fetch over XMLHttpRequest.