jquery - Using ajax with jQM and seeing duplicate POSTs -
i'm noticing ajax being called several times resulting in duplicate entries in mysql. what's deal? can see in code?
$("#form-addcomment").live('submit', function(e) { e.preventdefault(); var values = $(this).serializearray(); values = $.param(values); $.ajax({ type: "post", url: "/components/m/actions/index.php", data: "command=comments_add&" + values, datatype: "html", success: function(data){ alert(data); return false; } }); return false; });
you having problems multiple event binding, should fix problem:
$(document).off('submit', "#form-addcomment").on('submit', "#form-addcomment" ,function(e) { e.preventdefault(); var values = $(this).serializearray(); values = $.param(values); $.ajax({ type: "post", url: "/components/m/actions/index.php", data: "command=comments_add&" + values, datatype: "html", success: function(data){ alert(data); return false; } }); return false; });
there other ways of multiple event binding, find out more take @ other article , search chapter called prevent multiple event binding/triggering: https://stackoverflow.com/a/14469041/1848600
Comments
Post a Comment