所以我正在构建一个通知系统,当我点击onclick按钮时,它会打开包含通知的div。与此同时,我想更新数据库,然后显示的红色图像将消失。
我如何编码ajax以获得onclick切换?
HTML:
<a href="#" onclick="toggle('alert_dropdown');">
<div class="alert_header_item" id="alerts"></div>
</a>
<div style="display:none;" id="alert_dropdown" class="alert_dropdown">
<div style="padding: 5px; width: 290px; max-height: 50%; overflow: hidden;">
JavaScript的:
<script type="text/javascript">
//onclick code here
$.ajax({
type: 'GET',
url: 'readnotifications.php',
data: {id: user_id},
}).success(function(data) {
// do what you need to do as notifications were read.
});
</script>