How to update <div> without reloading the whole page (ajax)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ullasvk
Forum Newbie
Posts: 21
Joined: Fri Feb 13, 2009 11:55 pm

How to update <div> without reloading the whole page (ajax)

Post by ullasvk »

Hello Friends,
i am newbie to Ajax and PHP.After a lot of search on the internet i was able to learn Ajax.
I have a page in which there are many image buttons. I wrote code for all image buttons using Ajax to retrieve data on click from the database. I have a <div> in the same page which retrieves data from the database at the page loading time. But what i need is ,whenever i click the image button it must retrieve value from the database as it is doing know and also update the <div> in the same page with new values from the database. I am able to retrieve value from the database for the image button, but unable to update the <div> with the new values.
Please any one help me, if not can anyone give me an idea how to do this.
Please...............

Thanks in Advance.
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: How to update <div> without reloading the whole page (ajax)

Post by Reviresco »

Assuming your Ajax (javascript) function takes two variables: the name of the script (php) to call, and the name of the div to update:

Code: Select all

getData(script, div);
So you need to write a script that gets the info from the database, and then echoes (prints) the results in the format you want.

So if the name of the script is get_info.php, and the name of the div to update is "mydiv":

Code: Select all

getData('get_info.php', 'mydiv');
and you call that function in an onclick, onkeyup, etc. on your button.
Post Reply