Simple Ajax , Populate div with data from php file.

Heres a quick and dirty lowdown on how to populate a div with some data from a php file.

Lets say you have a php file called helloworld.php
And it contained:

echo "Hello World!!!!";

Now, if you run this php file it will be a nice white page with just hello world in it.
What if you had a really cool website and wanted this data in a div on your website but you dont want to use frames etc.

Well, We can use Ajax to call your php script and then put any output from that script into any div you want on your webpage.

So on your html page put this code in:

<script type="text/javascript" src=""></script>
<script language="javascript" type="text/javascript">
function getdata() {

The above will call the google Ajax library and create a function we can use to populate our div ( In this case the div will be called JEFF )

Whenever you call that javascript function it will now populate a div named JEFF with the output of helloworld.php

<div id="JEFF">Output will appear here</div>
<a href="javascript:getdata();">ClickMe</a>

You could use a javascript timer to call the php script an dupdate the div as often as you want, Or have it update on a link click..


7 thoughts on “Simple Ajax , Populate div with data from php file.

  1. Genial fill someone in on and this post helped me alot in my college assignement. Gratefulness you on your information.

  2. Hi! Quick question that’s totally off topic. Do you know how to make your site mobile
    friendly? My website looks weird when browsing from my iphone.
    I’m trying to find a template or plugin that might be
    able to correct this issue. If you have any suggestions, please share.


  3. Hi mates, its impressive article about teachingand
    entirely explained, keep it up all the time.

  4. Pingback:

  5. Hurrah! In the end I got a blog from where I can genuinely get
    helpful facts concerning my study and knowledge.

  6. Pingback: tree removal melbourne

  7. Pingback: related internet page

Leave a Reply

Your email address will not be published. Required fields are marked *

seven − 4 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>