Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Setting Up for Ajax with PHP

    Not sure if this is the right place to post, but I have an existing static page that I'd like to break up into chunks in order to 'ajax-ify' my site, but I'm not sure the best way to go about it. I basically have links that correspond to content in a container div. I'd like to be able to swap the content in the container div accordingly with the help of ajax.

    What I'm stuck on is how exactly to separate it all. I'm thinking what I'd do is separate the content into different php pages and attach an ajax 'get' request to the links that gets the corresponding php page. If this is the correct way to go about it, how do I separate with php? Is it as simple as wrapping the DOM elements with a php tag and saving such as this:

    PHP Code:
    <?php
    <div id="content_1" class="content">blah blah blah</div>;
    ?>
    or do I need to use some kind of include(); function?

    Then I assume I'd have to set up an index.php page that collects all the separated php pages, but I'm not sure how'd I go about writing that either.

    I hope this is clear, I can mock up an example html file if it's too hard to follow?

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,189
    Thanks
    10
    Thanked 569 Times in 550 Posts
    you don't actually even need any php to do this. You can store all the content in seperate files and "ajax in" those files as needed. PHP could be used to provide the same type of separation: providing different content based upon the url. The php page would basically print the info you needed, as though it were a "normal" webpage, using the queryString to select what content you need.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #3
    New Coder
    Join Date
    Nov 2008
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    So then I'd separate everything into different html files? Like sidebar.html, content1.html, content2.html... etc, and then compile then in my index.html? Sorry, i'm a total n00b. I feel like i've googled the **** out of this and gotten so many ajax books at the library that go into detail, but i'm still missing some simple step. thanks for your reply.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,189
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by bonerton View Post
    So then I'd separate everything into different html files? Like sidebar.html, content1.html, content2.html... etc, and then compile then in my index.html? Sorry, i'm a total n00b. I feel like i've googled the **** out of this and gotten so many ajax books at the library that go into detail, but i'm still missing some simple step. thanks for your reply.
    there are three typical approaches to this task:

    1. server-side processing. This is where you use simple SSI, PHP, ASP, etc to bundle pages together into a single file right before it's delivered to the client.
    pros: always updated, single file delivered to client, good client performance.
    cons: server processing lowers the # of clients per hour you can serve.


    2. client-side processing. This is where AJAX or JSONP is used to inject content into an HTML shell. My blog is an example.
    pros: always updated, less work for server than includes, allows part caching.
    cons: slower client performance, more prone to caching problems.


    3. templating. this is the procedure used by editors like dreamweaver templates and library items. The separate files are combined by the editor and saved into a single HTML file which is then served to the client.
    pros: lowest server resources of all methods;highest # of clients per hour. single file results in high client performance.
    cons: not self-updating, editor must run a site update to update the built page with new/altered content.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #5
    New Coder
    Join Date
    Nov 2008
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    hmm, great info, thanks a lot rnd me! I guess i'm gonna move this into another thread since most of my questions now are concerned with the details of achieving this with prototype and scriptaculous.


  •  

    Tags for this Thread

    Posting Permissions

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