Jump to content

ajax and using the back button


lional

Recommended Posts

I have created a site using mysql and php.

When using sessions for the shopping cart, if the user presses the browser back button the previous page is not displayed only a page that says that this page has expired.

I posted on the php help section and I was told that this can be done with AJAX. I am very new to AJAX in fact my book only arrived today.

Can someone point me in the right direction so that I can accomplish the above.

Link to comment
Share on other sites

do you have an example page?

 

Are you saying the following happens:

-User navigates to an Item page

-User clicks BUY ITEM, which does a POST to the shopping cart, adding the item

-User navigates to another page

-User clicks BACK BUTTON, which should take them to the shopping cart page, but it says the page has expired and asks if they want to re-post the data?

Link to comment
Share on other sites

I have a page with all the products listed with a text box next to each item where the user can enter the quantity. This allows the user to select more than one item and purchase them all with one transaction. So he doesn't add one product to the cart and then add the second. So basically all the items are added to the cart and then the cart is viewed and the user can proceed to the checkout. But if the user adds say 5 products to the cart and then he goes to the view cart. If he clicks the back button to go back to the items page it says the webpage has expired.

 

 

Link to comment
Share on other sites

There is a navigation button that takes the user to the items page. The whole site was written so that the user can make all their selection once and then procedd to the checkout. On the view cart page the user can change their quantities and delete items.

The site is a photo to canvas site so the user uploads their image and the items are various sizes of canvas that they would like the image to be on.

at the end of the process the user can select a second image and repeat the process. 

Link to comment
Share on other sites

i still don't understand where all your POSTs are happening. but what i do to avoid that message, is when I have a POST, i process the data, then use a header('Location: ...'); call to send them to a page (even if it's the same page).

 

So, if you have something posting to cart.php for example, i would do this:

<?php

if($_SERVER['REQUEST_METHOD'] == 'POST'){
  //New items are being added
  //process those items here, saving the info into $_SESSION
  //Now send the page back to itself
  header('Location: '.$_SERVER['PHP_SELF']);
  exit;
}

//Now start the shopping cart
//Get all the info for the cart from $_SESSION

?>

 

make sense? this will also make it so if they refresh the page the POST goes to, it won't ask them if they want to resend the data

 

p.s. - can a mod move this back to PHP?

Link to comment
Share on other sites

go to the site www.canvasprintshop.co.za

On the home page there is an order button which allows you to upload your image (image must be greater than 300K), then you select your edging, on the next page you select your finish, and then on the following page you select your items and press the order button. That will take you to a view cart.if you press the back button from this page you get the page expired

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.