# Do I understand well?

**URL:** <https://forum.freecodecamp.org/t/do-i-understand-well/311179>\
**Category:** General\
**Created:** [September 2, 2019, 4:30am UTC](https://forum.freecodecamp.org/t/do-i-understand-well/311179 "2019-09-02T04:30:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meditsh](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@Meditsh](https://forum.freecodecamp.org/u/Meditsh)\
**Post date:** [September 2, 2019, 4:30am UTC](https://forum.freecodecamp.org/t/do-i-understand-well/311179/1 "2019-09-02T04:30:15Z")

</div>

Hi,

I am not sure that I understood this code meaning :

```auto
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);

```

As I read in the exercice Data Visualization Certification \> “JSON APIs and Ajax: Post Data with the JavaScript XMLHttpRequest Method” : the if statement allow us to wait until "the operation is complete " and “the request is successful”. Which means we use the request in a synchronous way.  
But the asynchronous use of the fonction is allowed by the 3rd argument of the “open” function (which is set to true).  
Should’nt it have the same effect to edit this argument to “false” ?

I trully understand that the exercices are written with a didactic purpose, I just want to be sure to understand everything.

Thank you per advance 🙂

---

<div class="post-metadata">

**Author:** ![Layer](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/layer/32/82898_2.png) [@Layer](https://forum.freecodecamp.org/u/Layer)\
**Post date:** [September 2, 2019, 10:54am UTC](https://forum.freecodecamp.org/t/do-i-understand-well/311179/2 "2019-09-02T10:54:39Z")

</div>

Quoting from [MDN: xmlHttpRequest.open:](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open)

> Async  
> An optional Boolean parameter, defaulting to `true` , indicating whether or not to perform the operation asynchronously. If this value is `false` , the `send()` method does not return until the response is received. If `true` , notification of a completed transaction is provided using event listeners. This _must_ be true if the `multipart` attribute is `true` , or an exception will be thrown.

To answer your question:

> Should’nt it have the same effect to edit this argument to “false”

If you set the third parameter to `false` the send method will be _blocking_, means that any instruction after `req.send(userName)` won’t be executed until you receive a response; viceversa, if set to `true`, allow your code to continue its execution and when you receive a response it will be managed by the callback (which will be triggered in any case when the response is received)^^

Good luck on your learning path! 😄

---

<div class="post-metadata">

**Author:** ![Meditsh](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@Meditsh](https://forum.freecodecamp.org/u/Meditsh)\
**Post date:** [September 2, 2019, 6:48pm UTC](https://forum.freecodecamp.org/t/do-i-understand-well/311179/3 "2019-09-02T18:48:25Z")

</div>

Now I understand how I muddled up the asynchonous behavior and non-blocking behavior. I am glad that I asked for it 😃

Thank you so much @Layer for your complete and helpful answer.

Have a nice day 🙂

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 9:28am UTC](https://forum.freecodecamp.org/t/do-i-understand-well/311179/4 "2021-01-17T09:28:34Z")

</div>

Closed on January 17, 2021, 9:28am UTC


