Ajax Request open and send methods

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Ajax Request, open() and send() methods

In Ajax if we want to send the request to the server,  we have 2 methods in XMLHttpRequest object to do this work,  those are open() and send().

Actually open() method will opens the connection with the server and send will sends our request object to the server.

Let we took the XMLHttpRequest object into one variable called obj then

obj.open(” POST “, ” destination URL “,true);

  • open() method has 3 parameters, first parameter having the values POST/GET this is depends on our requirement, my choice is always POST, because its having security than GET
  • Second parameter is the destination, to where we need to send the request.  It may be any file path or url or url patterns [ in java ] or what ever
  • Third parameter having the values true/false,  actually true means we are opening Asynchronous data transfer, and false means Synchronous

 Actually, Synchronous means at a time we can send single request and we need to wait for the response before send the second request, and Asynchronous means we can send the second request before we get the response of first request, Ajax is the example of this Asynchronous type.

I already told about this in the introduction right….!!!!!!!!

Finally send() method will send the request object to the server.