我正在使用PHP_Storm
,我正在建立一个网站,我需要在其中添加购物车选项。
我想要的是一个简单的按钮,以获取特定分类reference
的( reference ( $this->reference = bin2hex(openssl_random_pseudo_bytes(10)).time();)
已经在网页中声明,我可以将其指定为按钮的值)并将该数据保存为实体cart
中的字符串。 JS或AJAX或其他任何可能的方式。你们能帮助我吗?
使用AJAX来做到这一点,
$.ajax({
url:'store-data-url',
type:'post;
data:{
//data-to-store
},
success: function(response){
//get response
console.log(response);
},
error:function(error){
//get error
console.log(error);
}
这是如此简单,希望它有所帮助
将PHP变量从浏览器发送到服务器的简单方法:
<form action="..." method="post">
<input type="hidden" name="value" value="<?php echo $this->reference ?>" />
<input type="submit">
</form>
在服务器上,您必须将$_REQUEST['value']
的值存储到数据库中。