By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

AJAX Example

RamananKalirajan
100+
P: 607
Hi Guys I am new to AJAX. I am in need of an AJAX example which includes Prototype. My Requirement is from a prototype i must create a AJAX call and call a HTML file or Java file without server and print the response back in the caller file. If you guys can help me put pls help me

Regards
Ramanan Kalirajan
Jul 24 '08 #1
Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,343
please post what you have so far ... so that we have something to work with ...

kind regards
Jul 24 '08 #2

RamananKalirajan
100+
P: 607
please post what you have so far ... so that we have something to work with ...

kind regards

Thank you very much Mr. Gits I completed my Task. The code is

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. </head>
  4. <form>
  5. <input type="button" id="myButton" value="Click Me">
  6. <br/>
  7. <div id="container"></div>
  8. </form>
  9. </html>
  10. <script src="prototype.js"></script>
  11. <script language="javascript">
  12. $('myButton').observe('click',function(){
  13.          var myObj = new myClass();
  14.          myObj.test(); 
  15. });
  16.  
  17. var myClass = Class.create({
  18.        initialize :  function(){
  19.       },
  20.  
  21.       test : function(){
  22.          new Ajax.Request("MyNew.html",{
  23.                     method: 'get',
  24.                     onSuccess: function(transport){
  25.                         var res = transport.responseText;
  26.                         new myClass().myHandler(res);
  27.                     }
  28.             });
  29.        },
  30.  
  31.            myHandler : function(val)
  32.            {
  33.                  var cont = $('container');
  34.                  var content = val;
  35.                  cont.update(content);
  36.            }  
  37.   });
  38.  
  39. </script>
While running this file please create an ordinary HTML file with the name "MyNew.html" and have the latest Prototype.js file within the directory.
Those who are starting with AJAX can use this code. It will be very useful.

Regards
Ramanan Kalirajan
Jul 25 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.