Newsletter |
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);
obj.send();
- 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.
You Might Also Like
::. About the Author .:: | ||
thanks..its very useful for me..whole site is helpful.!!
this is very useful
Sir where i need to have this url file in my public folder or anywhere else?
thanks! Nice Explanation
Thank you! It’s very easy to learn ajax from this site
how to send the value of user submitted value to the servlet?
Hello Sir,
Its a very nice page to learn Ajax.After reading the whole pages with explanation related to Ajax I found it is a piece of cake.
But I am stuck on a problem ,while we write the destination file name in open function its not executing.
I mean i am not able to get a response in the form of text on my page.
Eagerly waiting for your response.
Thanks.
Its very good website 🙂 .thanks a lot for this valuable website 🙂
good explanation ,loving ur tutorials to learn. Thanks a looooooooooooooooooooottttttt to Java4s Teammmmm.
Hello Sivateja Sir, I have followed all your step to run this ajax example but when I clicked on button then In div section it showing message “undefined” rather than ajax.txt file.
Superb and Thank You!
good explanation!