GET or POST Method In XMLHttpRequest Object

This article tell you about GET and POST Method in XMLHttpRequest Object.
  • 2872

GET method is easy and faster compare than POST method, and used to most access.

However, POST request when

  • If A cached file is not present in an option (update a file or database on the server)
  • When client have to send large amount of data to  the server (because POST has the no limitation)
  • When user have to send some secure or unkown characters). Because POST method is more robust and secure compare than GET method)

The url - A File On a Server

Url parameter of the open() method, is an address to the file on a server.



Note: Here the type of file can be any like .txt  and xml or and server file like .asp and .php

Asynchronous - True or False?

When user want to send the request asynchronously, the async parameter of the open() method has to be set to true:"GET","xmlhttp_info.txt",true)

when user send request a asynchronously  the huge improvement for web developers. Mostly task which is perform on the server take more time.

But when sending a request synchronously, then JavaScript does not have to wait for the server respone.

but instead of it

  • Can excites other JavaScript while waiting for the server response.

  • It only work with response when response is ready


When assign async=true, then a execute a specific function when the response is ready in the onreadystatechange event:

  if (xmlhttp.readyState==4 && xmlhttp.status==300)



When assign async=false, then also change the third parameter in the open() method to false."GET","xmlhttp_information.txt",false);

The assigning async=false is not recommended, but a few small request this can be ok.

If you remember that that when JavaScript will NOT continue to execute, until the server response is ready. When server is too busy or slow than application will hang or stop.

Note: When you assign async=false, do NOT write an onreadystatechange function - only put the code after the send() statement:"GET","xmlhttp_information.txt",false);


Further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.