嗨,我的网页上有一个按钮。一旦我点击该按钮,弹出框将显示并在2秒后关闭。 在这里,我需要在后台运行一个PHP代码,其中包含增加按钮命中计数的代码。 我在下面给出了我的代码 它无法正常工作
<!doctype html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:400,500">
<link type="text/css" rel="stylesheet" href="popModal.css">
</head>
<body>
<button id="notifyModal_ex1" class="btn btn-primary">Example</button>
<div id="content2" style="display:none">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<script src="popModal.js"></script>
<script>
$(function(){
$('#notifyModal_ex1').click(function(){
$('#content2').notifyModal({
duration : 1500,
placement : 'center',
overlay : true,
type : 'notify',
url: 'add_count.php',
onClose : function() {}
});
});
});
</script>
</body>
</html>
答案 0 :(得分:0)
在add_count.php中,您可以定义计数器 - 您可以将其命名为&#34; count&#34;并使用会话:
$_SESSION['count'] = (int)$_SESSION['count']+1;
以后,无论您需要在哪一方面,都只需回显$_SESSION['count']
变量。
答案 1 :(得分:0)
To&#34;在后台运行PHP&#34;您可能想要进行AJAX调用。由于您已经使用了jQuery,因此您可以使用它。一旦PHP脚本返回结果,您可以再次关闭模式;将更新后的计数包含在其中可能是有意义的,这样您就可以在按钮中显示它。
你应该自己做一些研究,找出AJAX,API和JSON是什么。