weixin_33709609 2010-11-16 11:48 采纳率: 0%
浏览 15

jQuery-ajax控制数据发布

I do not understand why but sometimes when I use .post() function the data are posted more than one time how can I control and stop this think? Thanks in advance.

best regards That's my code:

case "mod" :
            $.post("./php/"+eti[indice]+".php",
                {azione: "carica", contratto:contratto},
                function(xml)
                {
                    if ($("status", xml).text()=="1")
                    {
                        scorriDati(xml);
                        $.post("./php/"+eti[indice]+".php",
                        {azione: "vedi", contratto: contratto },
                        function(xml)
                        {
                            if ($("status", xml).text()=="1")
                            {
                                var lun=$("#"+eti[indice]+"_"+indice).length;
                                if (lun == 0)
                                {
                                    $("#scheda_sch").append("<div style='clear:both'><div style='float:right' id='mod_def'><div id='"+eti[indice]+"_"+indice+"' class='bt'>modifica</div></div></div>");
                                    scorriDati(xml);
                                }
                            }
                            else
                            {
                                $("#scheda_ris").html("<p><img src='./img/validyes.png' alt='ok'> Attenzione!<br>codice non trovato!</p>");
                            }
                        },'xml');
                    }
                    else
                    {
                        $(xml).find("errore").each(function()
                        {
                            $("#scheda_ris").append("<img src='./img/validno.png' alt='errore'> <span style='color:red'>"+$(this).text()+"<br></span>
");
                        });
                    }
                },'xml'
            );
        break;

The problem is generated when I click on modifica, I get more than one button and data are posted several times..

ciao h

  • 写回答

2条回答 默认 最新

  • 斗士狗 2010-11-16 11:55
    关注

    Generally this kind of things happens when end users having habit to double click the buttons uses your app. This may cause post request twice if you are not disabling the button after first click

    I hope if you add code to appropriately handle this thing and that will resolve your problem. You can do following things for solution:

    • Disable the control that causes the post event on first occurrence
    • you can bind click and double click both events to same function and then use global variable that stores count of click, if count is > 1 then don't click it. In result of post you can make count 0 again.

    Hope this will help

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器