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

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

You probably call the .post() twice.