Php 将onclick/toggle与Ajax合并
因此,我正在构建一个通知系统,当我单击onclick按钮时,它会打开带有通知的div。同时,我想更新数据库,如图所示,显示的红色图像将消失 如何编写ajax代码以获得onclick切换 HTML:Php 将onclick/toggle与Ajax合并,php,ajax,Php,Ajax,因此,我正在构建一个通知系统,当我单击onclick按钮时,它会打开带有通知的div。同时,我想更新数据库,如图所示,显示的红色图像将消失 如何编写ajax代码以获得onclick切换 HTML: <a href="#" onclick="toggle('alert_dropdown');"> <div class="alert_header_item" id="alerts"></div> </a> <div style="dis
<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;">
<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>
JavaScript:
<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;">
<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>
//点击这里的代码
$.ajax({
键入:“GET”,
url:'readnotifications.php',
数据:{id:user_id},
}).成功(功能(数据){
//在读取通知时执行您需要执行的操作。
});
切换(“警报”下拉列表);YourajaxFunction()代码>@Up这不是很好,因为无论ajax请求成功还是失败,都可以通过这种方式切换下拉列表。由于超时、代码错误或任何ajax操作随时可能失败的原因。