Thread: "AJAX" pondering.

  1. #1
    Registered User AloneInTheDark's Avatar
    Join Date
    Feb 2008
    Posts
    74

    "AJAX" pondering.

    I'm writing a tech forum, well it's actually CRM which will handle 3 sites. anyway, trying to get on board with all this "AJAX" hype.

    I noticed something very cool in this forum, when I hist "Post quick reply", it posts my text to server and gets a reply... so far so good. I know how to.

    Now, funny thing happens, it gets the text and creates a new "reply" beneath the last reply on the bottom of screen without having to reload the whole page.

    Anyone got an idéa how you can do that?

    I have a guess that it perhaps have an empty DIV tag with a specific ID so it pushes the text|html into it ( innerHTML ) via javascript.

    However, this can be done "unlimited" times, so if I were to have :

    *reply*
    *reply*
    *reply*
    <DIV ID="1"></DIV>

    the above could work once. But as soon as I need to do another quick reply, there is no more "DIV-1" since I already filled it. I would need :

    *reply*
    *reply*
    *reply*
    <DIV ID="1"></DIV>
    <DIV ID="2"></DIV>
    .
    .
    .

    hm... I hope this thread make any sense *lol* , hard to explain what I mean.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    AJAX uses client side scripting, so if it's there you can see it in the page source. A quick look and I saw a reference to http://cboard.cprogramming.com/clien...post_loader.js which may be what you look for. Check it out.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User AloneInTheDark's Avatar
    Join Date
    Feb 2008
    Posts
    74
    Yepp, but I thought it would be more fun pondering about this and hear other people's idéas on how it could be done. I'll check out that source. Thanks.

  4. #4
    Registered User AloneInTheDark's Avatar
    Join Date
    Feb 2008
    Posts
    74
    Just found this :

    http://www.dustindiaz.com/add-and-re...th-javascript/

    Code:
    function removeElement(divNum) {
      var d = document.getElementById('myDiv');
      var olddiv = document.getElementById(divNum);
      d.removeChild(olddiv);
    }
    Code:
    function addElement() {
      var ni = document.getElementById('myDiv');
      var numi = document.getElementById('theValue');
      var num = (document.getElementById('theValue').value -1)+ 2;
      numi.value = num;
      var newdiv = document.createElement('div');
      var divIdName = 'my'+num+'Div';
      newdiv.setAttribute('id',divIdName);
      newdiv.innerHTML = 'Element Number '+num+' has been added!
     <a href=\'#\' onclick=\'removeElement('+divIdName+')\'>Remove the div "'+divIdName+'"</a>';
      ni.appendChild(newdiv);
    }
    Cool stuff!
    Last edited by AloneInTheDark; 02-10-2008 at 06:25 AM. Reason: added a line break in the code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pondering
    By andrewV in forum Game Programming
    Replies: 14
    Last Post: 01-04-2005, 07:26 AM