2012-09-07 46 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; 
}