Newsletter

Ajax Request, open() and send() methods

Ajax » on Aug 25, 2011 { 12 Comments } By Sivateja

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 .::

Java4s_Author
Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

12 Responses to “Ajax Request, open() and send() methods”
  1. sarang says:

    thanks..its very useful for me..whole site is helpful.!!

  2. pramod says:

    this is very useful

  3. Neeraj says:

    Sir where i need to have this url file in my public folder or anywhere else?

  4. sudheer says:

    thanks! Nice Explanation

  5. Mahendra says:

    Thank you! It’s very easy to learn ajax from this site

  6. shri says:

    how to send the value of user submitted value to the servlet?

  7. Ankita says:

    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.

  8. dinesh says:

    Its very good website 🙂 .thanks a lot for this valuable website 🙂

  9. Naidu says:

    good explanation ,loving ur tutorials to learn. Thanks a looooooooooooooooooooottttttt to Java4s Teammmmm.

  10. Hridesh Yadav says:

    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.

  11. Deepak says:

    Superb and Thank You!

  12. prakash says:

    good explanation!

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.