SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    is it possible to fill a div with AJAX?

    Is it possible to fill a div tag with ajax?

    I was looking at this:
    http://www.dhtmlgoodies.com/index.ht...chained_select
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    SitePoint Enthusiast bdude's Avatar
    Join Date
    Jan 2006
    Location
    In a house.
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're using jquery you can use this code:
    Code:
    $("#links").load("/Main_Page #p-Getting-Started li");
    SUPPORT FOR NEW BLOGGERS - TRY THE Blogging Forum

  3. #3
    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)
    If you're not using a library that supports ajax, the tools that you would use for filling the div tag depend on what you're going to put in there.

    Bulletproof Ajax has some good examples to work from, and provides code from the book that you can use. You'll be wanting one of the fetch scripts from chapter 4.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my intention is to hook it up with a php file with a get method. The php file will retrieve from the database.
    Compare bible texts (and other tools):
    TheWheelofGod

  5. #5
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bdude View Post
    If you're using jquery you can use this code:
    Code:
    $("#links").load("/Main_Page #p-Getting-Started li");
    WHat's jquery? JavaScript query?
    Compare bible texts (and other tools):
    TheWheelofGod

  6. #6
    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)
    If it's getting information from the database then the easiest way to pass data is in the XML format. Then javascript can interpret the data and and do whatever you like with it.

    See the fetchxml.js file from Chapter 4 of Bulletproof AJAX

    As far as jquery goes, that's a light-weight library for dom traversal and ajax functionality. If you will be using a certain amount of its features it's worth using.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah i'd do it lie pmw said. Make an ajax request to your php and return some xml from that script.

    If you don't know much ajax then i'd suggest using prototype or jquery to do that hard work for you....both allow you to make safe ( cross-browser) ajax requests with just a few lines of code.

    prototype can do it with Ajax.updater method which takes care of the update of the div also in ttwo lines of code:

    say if you div you wanted to fill was called placeholder. You'd do something like this....replacing the 'someurl' with your url

    Code JavaScript:
    var AjaxRequest = new Ajax.Updater('placeholder', someurl,  
     { method: 'get',  parameters: enteroptional params here});
    }

    There you go...now your placeholder div will be filled with whatever your php script returns


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
  •