2012-09-07 48 views
0

後面的行爲在我的PHP的網站,當用戶增加了一些自己的購物車我觸發URL變化,使某些功能,並觸發頁面上:改變瀏覽器PHP

原始地址

/category/product/10 

新的URL

/category/product/10#addtocartbutton 

網址將成爲

/category/product/10?x=1 

的方法:

/category/product/10 
/category/product/10#addtocartbutton (user clicks an onclick href to submit form) 
/category/product/10?x=1 (the form adds the item to the session and appends this URL querystring) 

的問題時,他們按BAC b

+0

那麼,您的新網址'/分類/ product/10#addtocartbutton'或'/ category/product/10?x = 1'? –

+1

不要試圖做到這一點。如果可以,請重新設計應用程序,以便每當用戶按下後退按鈕並重新提交表單時,都不會發生任何錯誤。 – reinierpost

回答

0

或試圖pushState東西。你應該能夠根據你的需要操縱你的歷史。

0

一個好主意是讓add函數將您重定向到產品頁面而不顯示查詢字符串。因爲我不知道你怎麼寫你的附加控制器,很難給你一個確切的代碼示例...

編寫PHP控制器添加類似:

function add_to_cart() 
{ 
    add $_GET['x'] to session; 
    redirect back to product page; 
}