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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem reloading frame with dynamic data.

Status
Not open for further replies.

dessie1981

Programmer
May 9, 2006
116
GB
Hi everyone.

I have developed an online store and i am trying to add a feature which shows how many items the user has in their basket.

I have 3 frames, main - where there is a table of results and text field with a quick add button in each row of the results.

SideFrame - Search tools

TopFrame - Show's some images and links, but also the number of items in the shopping basket.

Everytime the user adds a products i am
reloadading the top frame to refresh the "number" that the user sees.

The problem is that this seems to only work intermittently
It does not seem to reload the frame everytime.

I am using javascript to reload the frame.

<form name="myform" action = "<?echo $_SERVER['PHP_SELF'];?>?empty=1" method="POST">
<input name="Submit" type="submit" class="form-button" value="Empty Basket" OnClick="parent.topFrame.location.reload();" />
</form>


here is the php i have used to calculate the no of items in the basket.

if (count($_SESSION['quantity']) != 0)
{
$newval = 0;
foreach ($_SESSION['quantity'] as $val)
{
$newval = $val + $newval;
}
}
else
{
$newval = 0;
}


any ideas???

Regards
Dessie
 
Do you get different behaviors with different browsers? I'm wondering if this isn't a caching problem that the different caching software in different browsers would change.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Hi Sleipnir,

It seems to be the same in MS Internet explorer and mozilla Firefox.

Regards
Dessie
 
When the user adds an item or items to the basket the main page itself is reloaded, do you think that this has an effect on the topframe reloading??

Regards
Dessie
 
Do you know if there is a way to count the number of reloads there is in php??

Regards
Dessie
 
after using a session variable i can confirm that the javascript is working fine as the page is reloading everytime.

I think my php is ok, i return $newval btw

Anymore ideas???

There does not seem to be much of a pattern here.

Regards
Dessie
 
Of course, I am not a JavaScript expert and this is not a JavaScript forum, but this sounds to me like some kind of timing problem. Particularly if the update of the cart display happens as part of an onclick event.

For all this to work, you need first for the the user to submit his chosen item and quantity to the server then followed by the update of the cart display. What mechanism in your code quarantees that?





Want the best answers? Ask the best questions! TANSTAAFL!
 
Hi again Sleipnir,

Yes prob is a timing problem, do you have any suggestions as to how i could reload the frame separately??
As the onclick event reloads relaods the main frame also and this is where items are added to the cart.

Regards
Dessie
 
sorry to butt in here, but this reminds me of another user's problem reported in this forum!

dessie, can you confirm whether:

1. you are using sessions to hold the cart data
2. you are testing this code on localhost

if so, it is possible that you are hitting a race condition with the update to the session files. this can be overcome by adding the function call
Code:
session_write_close();
just before you send the output to the browser.

sleipnir214 wrote a session FAQ in this forum which first alerted me that there could be a race condition with sessions.
 
Silly idea: make your onClick like this:

onClick="updatemainpage();wait(2000);updatetoppage();"

Maybe it just needs extra time sometimes.

I think it's wait(). I have too many languages in my head.
 
Depending on where the JavaScript code resides (in which window), that may or may not work.


I think that if when the "quick link" is selected and the main window refreshes, perhaps when PHP rebuilds the page it can include at the very end of the page the code necessary to refresh the cart window.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Or you could put an onLoad attribute on the body tag of the main window.

Code:
<body onLoad="updatetoppage">

 
Depending on how the main page PHP code is written, it may be necessary for the reload of the cart window to happen as late as absolutely possible. This could be accomplished by JavaScript at the end of the main page's HTML stream.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Hi again everyone,

I have it working now by adding a sleep(2) into my top frame page, i think it is just a timing issue alright.

In response to jpadie , yes i am using sessions for my cart and quantity.

Ill try your suggestion and see what happens. (session_write_close();)

Regards
Dessie
 
session_write_close(); did not seem to work,
I think this only needs to be used when two script are using sessions at the same time, i dont think this is what is happing in my case.

I think i will stick with the sleep() function.



Regards
Dessie
 
actually <body onLoad="parent.topFrame.location.reload();"> seems to be the best solution as when the user adds to the cart the main page is reloaded.

Regards
Dessie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top