Get all updates of Java4s
Follow Us: Email Newsletter

Ajax Request, open() and send() methods

Ajax » On Aug 25, 2011 { 11 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” 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.




You Might Also Like

  ♦ About Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


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


  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!


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

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