Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP AJAX singe frame refresh (with MySQL update)

Status
Not open for further replies.
Apr 27, 2006
126
GB
Hi,

Hopefully this is the right place to ask this and you can help.

I won't (yet) dump any of the code we have written as 1) It doesn't work and 2) I feel we may have gone about this the wrong way and need to start from scratch. (i'll point out that we have all the MySQL stuff working fine, it's just the page refreshes that we are havnig issues with)

Goal (simplified):

A PHP page, arranged with css. Divided into 4 sections, each a named <div>.

In frame 1 we have a button which performs the following actions:
Code:
*Update a record in the DB (for this example, increase X integer by 1)

*Re-load frame 2 (which will query the DB for the value of X and display it)

*Re-load frame 1 (which will query the DB again as it loaded the first time, pulls various things back from the DB)

*NOT refresh any other frame other than 1 & 2  (this is our stumbling block)

It's clear that AJAX is the way forward, but we just can't seem to get it working, there are tutorials out there and we keep thinking we have it working, then we test it in IE6 and notice (due to slower page load times) that it is refreshing every frame (either that, or it's re-loading the background image on top and then sending it to the back, but I have no idea)

We have played so much it's getting to the point that we don't know what we have and haven't tried and we could really just do with some pointers so help us get started.


note: I am not schizophrenic, "we" is myself and a friend.


Thanks in advance for any advice.

________
clueless
 
i can provide a quick sample. but it sounds as though you have things more or less working.
I assume that you are using onclick events on links to fire your requests. if that is so, then to stop your page from refreshing you need to kill the link after the js has fired. this is as simple as adding to the js as follows:

Code:
<a onclick="somejsFunction(somevalue); [red]return false;[/red]">Click me</a>
 
Also if you are new to AJAX it can be worth trying a library.
I have done both my own scripts and using something like prototype or moo-tools. These libraries often have specific functions defined to update an are such as a div using its id and some info about the php script you are calling.

Also if you are using innerHTML, remember that all the content that is there will be overwritten when its updated, are the updates losing something in layout or styling?

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top