问题是,如何检查是否已单击链接?
<a href="laggtill.php">+</a>
<a href="laggtill.php">+</a>
(another document)
<?php
session_start();
$_SESSION['car'] = $_SESSION['car'] + 1;
$_SESSION['boat'] = $_SESSION['boat'] + 1;
header("Location: betalning.php");
?>第一个标签将一辆汽车添加到购物车中,第二个标签将一只船添加到购物车中。如何检测被单击的a标记中的哪一个,如果我现在单击任何a标记,那么车和船都将被添加到购物车中。
发布于 2014-12-13 01:05:29
可以将GET参数添加到链接中:
<a href="laggtill.php?add=car">Add car</a>然后在PHP文档中:
if($_GET['add'] == 'car'){
$_SESSION['car'] += 1;
}
// etc...这基本上是使用链接将数据从一个页面传递到另一个页面的最简单方法。
发布于 2014-12-13 01:12:31
你应该使用的概念。是阿贾克斯
每次点击和其他与浏览器有关的事情只发生在客户端(浏览器)上。
有些简单的办法可能是:
// Html
<a id="linkone" href="laggtill.php">+</a>
<a id="linktwo" href="laggtill.php">+</a>//Javascript
// Use jquery
$("#linkone").on("click", function(){
//function that send request to server
$.post('someurl.php', {})
.success(function(res){
console.log(res);
// If you stay here, the procces should be ended
})
// if you return false, the click dont redirect other window
// if you return true, the click redirect other window
return false;
});// php文件用于第一个链接
<?php
//capture values
// But only is a clic, then there is not values
session_start();
$_SESSION['car'] = $_SESSION['car'] + 1;
// If you want some simple, one file only works for one link
// For the other link, you should create other file same to this.
header("Location: betalning.php"); // With ajax dont use this line,
?>https://stackoverflow.com/questions/27454397
复制相似问题