<script>
function viewtopic(paymoney,_aid){
var dia=$.dialog({
title:'<center>查看权限</center>',
select:0,
content:'<center><p style="color:red;margin-top:5px;">支付'+paymoney+'积分</p></center>',
button:["确认支付","取消"]
});
dia.on("dialog:action",function(e){
if(e.index==1){
return false;
}
var _tid=_aid;
$.ajax({
type:"POST",
url:"{url}",
data:{tid:_tid},
datatype: "text",//"xml", "html", "script", "json", "jsonp", "text".
success:function(data){
data=$.trim(data);
if(data==2){
alert('先登录!');
}
if(data==1){
window.location.reload();
}
} ,
error: function(){
//请求出错处理
}
});
// console.log(e.index)
});
dia.on("dialog:hide",function(e){
// console.log("dialog hide")
});
}
</script>
用的zepto.min.js,用户点击确认会出现同时2次的请求,导致每次都消耗2次积分。请问有没有什么办法可以限制同时重复的2次请求,在服务处理没用,是同时插入数据库,都没法做判断。
没用过这个dialog,理论上点击确定不会触发2次事件的,加下面黑色的控制试试
function viewtopic(paymoney, _aid) {
var dia = $.dialog({
title: '<center>查看权限</center>',
select: 0,
content: '<center><p style="color:red;margin-top:5px;">支付' + paymoney + '积分</p></center>',
button: ["确认支付", "取消"]
});
var loading = false;
dia.on("dialog:action", function (e) {
if (loading) return false;
if (e.index == 1) {
return false;
}
var _tid = _aid;
loading = true;
$.ajax({
type: "POST",
url: "{url}",
data: { tid: _tid },
datatype: "text",//"xml", "html", "script", "json", "jsonp", "text".
success: function (data) {
loading = false;
data = $.trim(data);
if (data == 2) {
alert('先登录!');
}
if (data == 1) {
window.location.reload();
}
},
error: function () {
loading = false;
//请求出错处理
}
});
// console.log(e.index)
});
dia.on("dialog:hide", function (e) {
// console.log("dialog hide")
在后台做处理,如果存在这样的一条数据,就不进行插入。
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632