Jump to content

PHP AJAX specific frame update/refresh (with MySQL update)


shavenlunatic

Recommended Posts

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 having 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:

*Update a record in the DB (for this example, increase X integer by 1)

*Re-load (or update X within) 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 to help us get started.

 

 

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

 

 

Thanks in advance for any advice.

Link to comment
Share on other sites

im not 100% sure on this, however, im thinking that this can be done with pre-established javascript functions. For example.

 

say you need a javascript function to load a default page to a certain area.

 

<script language="javascript">
     ajax('DIVNAME','LOADING_PAGE.EXT');
</script>

 

or whatever your ajax command is, all you do is add that to end of your script and it should run it after done loading. just don't load the same page as it will simply loop forever. Me personally I use a div thats hidden via css (display:none; visibility:hidden;) and execute all mysql command through that. Then if needed I reload divs that need updating. I guess it depends on your coding preference.

 

Me personally I use a variation of 3 different ajax commands one to post forms, one to load smaller areas, & one to load large areas. This allows me to edit each one to specific needs. You may think about editing a ajax script to your needs. Most don't come with a loading animation which I think is essential as you want your visitors to know that there request has been taken and so they wont keep clicking and reseting the request.

 

To solve your problem have php files made to do exactly what you want them to do and then just execute them by loading them in a div.

 

For example, say you wanted to (increase X by 1) but the product was different each time. Well create increase.php and program it to variables and send the ajax command as ajax("DIVNAME'.'increase.php?id=XXXXX'); im sure you know what the php file should do after that. Now at the end of your query add a if($query){ RELOAD DEFAULT JAVASCRIPT } and that should do it.

 

This is somewhat similar to what I do with shopping carts, as I use the hidden div which i explained before to update the cart then refresh the shopping cart div to show updates.

 

Anyways I hope some of my examples and suggestions help in this endeavor as im not that good in ajax myself.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.