Outputting html for AJAX

Discussion in 'JavaScript' started by alphacooler, Jul 28, 2006.

  1. #1
    So in AJAX I want to call a php page that will output a table in a particular order. Then I would simply want to pop that table output into a DIV. Is this possible with responseText or do I need to do something with XML?

    I am VERY noobish when it comes to AJAX.

    Thanks.
     
    alphacooler, Jul 28, 2006 IP
  2. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,
    Try using this AJAX library:
    http://www.modernmethod.com/sajax/

    You only need to include a PHP file at the top of your script and do a couple of function calls. You can use it to call a PHP function from your HTML page using Javascript. It simplifies things a lot.

    Thomas
     
    coderlinks, Jul 29, 2006 IP
  3. AoaoSo

    AoaoSo Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you may use innerHTML
     
    AoaoSo, Jul 30, 2006 IP
  4. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Whether to use responseText or responseXml depends on the format of data that the server gives you. If it's in XML, then you'd use res
    ponseXml, otherwise use responseText.

    If the PHP script returns an HTML table, then just use responseText, and populate the div with innerHTML as suggested above.

    e.g.: This is the div:
    <div id="mydiv"></div>

    Your JavaScript should look something like this:
    document.getElementById("mydiv").innerHTML = yourXmlHttpObj.responseText;


    Otherwise if it was in XML, then you'd need to play around a bit with DOM.
     
    phper, Jul 30, 2006 IP