Jump to content


Photo

loading ajax script on the home page

ajax php mysql

  • Please log in to reply
1 reply to this topic

#1 alfnero

alfnero

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 20 March 2013 - 10:32 PM

Hello,

How I should do AJAX code to request the getSales.php script when the home page of the site is loaded? and display it in a div .


thanks


  • qbdrthwh, PureFrase, floaxispapsex and 5 others like this

#2 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 23 April 2013 - 07:38 PM

I would recommend using either the jQuery or Prototype library. I used jQuery more recently myself, so I can give you more examples with that library. The simplest snippet would be the following using the .load() method.

 

Your HTML may look like this:

<div id="sales_content">Our sales content will load here.</div>

Then, you would use the load method once the document is ready like this:

$(function(){
    // Grab the div container and load the sales page into it (replaces all content)
    $('#sales_content').load('getSales.php');
});

You can also specify more options for the load method such as a callback to invoke upon completion, what to do if there is an error, or you can even load just a page fragment instead of the whole page returned. Check the documentation for more information.

 

I would even advise putting some type of loading text and/or image in the container as the page is loaded from AJAX. You can also make a button that would refresh the content by simply calling the load method again. The possibilities are endless for how much you could play with it.

 

I do also recommend taking a look at jQuery UI where you can spruce up your page as well. If you are planning on making dynamic content on the page that is loaded when needed, I would recommend looking into using the Tabs widget; it supports AJAX loading upon selecting the appropriate tab.


Edited by Demonslay, 23 April 2013 - 07:39 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users