SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: Hello in ajax

  1. #1
    Non-Member
    Join Date
    Oct 2008
    Location
    Banned
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hello in ajax

    Can someone give me example code of how to click a button then display on teh screen Hello World in ajax??

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you may be confused as to what ajax actually is. here is what you asked for in Javascript?

    Code javascript:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Untitled Document</title>
            <link rel="stylesheet" type="text/css" media="screen" />
            <style type="text/css"></style>
            <script type="text/javascript">
    			function addEvent(element, event, callback) {
    				if (element.addEventListener)
    					element.addEventListener(event, callback, false);
    				else if (element.attachEvent) {
    					element["e"+event+callback] = callback;
    					element[event+callback] = function() {
    						element["e"+event+callback](window.event);
    					};
    					element.attachEvent("on"+event, element[event+callback]);
    				}
    			}
     
    			// add the window.onload event
    			addEvent(window, 'load', function() {
    				// get the button
    				var btn = document.getElementById('button');
    				// assign the onclick event to the button
    				addEvent(btn, 'click', helloWorld);
    			});
     
    			function helloWorld() {
    				alert('hello world');
    			}
    		</script>
        </head>
        <body>
     
            <input type="button" id="button" value="Hello world" />
     
        </body>
    </html>


  3. #3
    Non-Member
    Join Date
    Oct 2008
    Location
    Banned
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly is ajax. with a full explanation

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://en.wikipedia.org/wiki/AJAX

    Google is your friend


  5. #5
    Non-Member
    Join Date
    Oct 2008
    Location
    Banned
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whenever I google ajax it gives me tutorials and articles ;(

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally I think that is one of the best ways to learn. By example.


  7. #7
    Non-Member
    Join Date
    Oct 2008
    Location
    Banned
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like to learn by coding it too. tutorials and articles are worthless

  8. #8
    Non-Member
    Join Date
    Oct 2008
    Location
    Banned
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also i tihnk u misunderstood me. i tried out the code and all it is is an alert. I know how to do that lol. Im not a beginner programmer in JS. What I want is when I click a button for example on a new line or even next to the button is the words Hello to pop out of nowhere without reloading the page

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <button type="button" onClick="document.getElementById('foo').innerHTML = 'Hello!';">Click Me!</button><span id="foo"></span>
    This is not ajax, this is plain old javascript.

  10. #10
    Non-Member
    Join Date
    Oct 2008
    Location
    Banned
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know. That was my point. but I already found a tutorial on how to say hello world. Its in another thread I believe

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    The Bulletproof Ajax code archive starts off with a test ajax. The book is an excellent read too.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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