Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: AJAX Made Easy

  1. #1
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    3,285
    Tokens
    0

    Latest Awards:

    Default AJAX Made Easy

    Ever wanted to be the envy of your web designing friends and be able to do mega-trendy AJAX? Well, now you can with AJAX Made Easy, first, you need to get your framework, which is a file called easyajax.js! Here is the contents of it:

    Code:
    function ajaxobject() {
        var objType = false;
        try {
            objType = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e) {
            try {
                objType = new ActiveXObject('Microsoft.XMLHTTP');
            } catch(e) {
                objType = new XMLHttpRequest();
            }
        }
        return objType;
    }
    
    function ajax(url,elementContainer){
    	document.getElementById(elementContainer).innerHTML = '<strong>Loading...</strong>';
    	var theHttpRequest = ajaxobject();
    	theHttpRequest.onreadystatechange = function() {processajax(elementContainer);};
    	theHttpRequest.open("GET", url);
    	theHttpRequest.send(false);
    
    		function processajax(elementContainer){
    		   if (theHttpRequest.readyState == 4) {
    			   if (theHttpRequest.status == 200) {
    				   document.getElementById(elementContainer).innerHTML = theHttpRequest.responseText;
    			   } else {
    				   document.getElementById(elementContainer).innerHTML="<p><strong>Error!</strong> HTTP request return the following status message:&nbsp;" + theHttpRequest.statusText +"<\/p>";
    			   }
    		   }
    		}
    
    }
    That is the Javascript that does all the AJAX, now you need a HTML file that shows it off! Create a HTML file and place this in the head tags:

    Code:
    <script type="text/javascript" src="easyajax.js"></script>
    And then you are ready to do your uber leet AJAX. This AJAX library lets you replace the text on the page without moving between pages. This can even be used with onSubmit on forms!

    Now, create a span with an id of your choice. Here you go:

    Code:
    <span id="ID YOU CHOOSE"></span>
    Now create a hyperlink like this:

    Code:
    <a onClick="ajax('PAGE TO SHOW','ID YOU CHOSE EARLIER');return false;">Click here</a>
    Now, if you click on that link, first you will get a piece of text that says "Loading..." and then when it has finished getting the page it will display it - all done without iFrames or refreshing the page. My next tutorial will be AJAX with forms!



    i used to be NintendoNews. visit my blog or add me on twitter.
    need help with vista? i am a microsoft certified technology specialist in configuring windows vista and connected home integrator.. pm me for help!


    "I am the way, the truth, and the life. No one comes to the Father except through me"
    John 14:6 (NIV)


  2. #2
    Join Date
    Apr 2005
    Posts
    127
    Tokens
    0

    Default

    This thread deserves to be stickied.

  3. #3
    Join Date
    Jun 2005
    Location
    Manchester
    Posts
    3,187
    Tokens
    0

    Latest Awards:

    Default

    Hey,

    Nice one Tim. You was yapping on about AJAX on MSN and I didn't get you lol. Anyway i'll have to rep you some othertime for this as well :@

    - Dan

  4. #4
    Join Date
    Oct 2005
    Location
    East Midlands
    Posts
    1,898
    Tokens
    0

    Latest Awards:

    Default

    Ajax were made to sweat tonight.

    2-2 with Inter, were 2-0 up aswell.

  5. #5
    Join Date
    Jun 2005
    Location
    Manchester
    Posts
    3,187
    Tokens
    0

    Latest Awards:

    Default

    Hey,

    We're not talking about the football team but Anchrosymcious Javascript And XML.

    - Dan

    Quote Originally Posted by SHEEPY
    Ajax were made to sweat tonight.

    2-2 with Inter, were 2-0 up aswell.

  6. #6
    Join Date
    Oct 2005
    Location
    East Midlands
    Posts
    1,898
    Tokens
    0

    Latest Awards:

    Default

    Yes.. I know..

  7. #7
    Join Date
    Aug 2005
    Location
    Tunbridge Wells, Kent
    Posts
    5,063
    Tokens
    1,624

    Latest Awards:

    Default

    lol, i don't think you did know -.- but nvm Tim thats brill, im gonna use it ( MY V.I.P HAS DISSAPPERED )EDIT: Brought More
    Last edited by Flisker; 23-02-2006 at 07:08 AM.
    Never argue with an idiot, he'll drag you down to his level, and beat you with experience.

    Quote Originally Posted by Recursion
    *oh trust me
    *I would NEVER go ATi
    And 15 mins later...
    Sapphire ATI Radeon HD 5850 1024MB GDDR5 PCI-Express Graphics Card £195.73 1 £195.73
    *ordered.

  8. #8
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    3,285
    Tokens
    0

    Latest Awards:

    Default

    For my next AJAX project I'm going to make a server information thing.



    i used to be NintendoNews. visit my blog or add me on twitter.
    need help with vista? i am a microsoft certified technology specialist in configuring windows vista and connected home integrator.. pm me for help!


    "I am the way, the truth, and the life. No one comes to the Father except through me"
    John 14:6 (NIV)


  9. #9
    Join Date
    Nov 2005
    Posts
    807
    Tokens
    1,335

    Latest Awards:

    Default

    Wahey ajax is annoying me.. My connection script wont work or maybe its my server.. cos my script looks pretty valid..

  10. #10
    Join Date
    Aug 2004
    Location
    bristol
    Posts
    3,799
    Tokens
    0

    Latest Awards:

    Default

    Where did you get your script from?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •