javascript - Ajax form submit twice when include jcarousel script -
i'm using ajax submit form, when click button add cart form submit twice if remove jcarousel , form submit normal.
<form id="formrandom1473" name="formrandom1473" method="post" action="ajax_process.php?case=add_product_ajax&pid=1473"> <input type="hidden" value="1473" name="products_id"> <input type="hidden" value="1" name="qty"> <div class="add_to_cart_div"> <input type="image" border="0" id="add-to-cart-1473" title=" add cart " alt="add cart" src="includes/languages/english/images/buttons/button_in_cart.gif"> </div> </form> <script type="text/javascript"> $(document).ready(function() { $("#add-to-cart-1473").click(function () { var formrandom1473 = $("#formrandom1473"); formrandom1473.submit(function () { $.ajax({ type: formrandom1473.attr("method"), url: formrandom1473.attr("action"), data: formrandom1473.serialize(), success: function (data) { $("#output").html(data); $(".message_div").addclass("message_success").slidedown().delay(6000).slideup(); // div success $(".cart_counter").load("ajax_process.php?case=cart_counter"); // load new quantity / quantity $(".shopping_cart_box").load("ajax_process.php?case=shopping_cart_box"); // load new shopping cart box / product $(".cart_dropdown").load("ajax_process.php?case=cart_dropdown"); // load new shopping cart box / product } }); $("formrandom1473").unbind(); return false; }); /* effect */ var productx = $("#cart-image-1473").offset().left; var producty = $("#cart-image-1473").offset().top; var basketx = $("#boxcart-content").offset().left; var baskety = $("#boxcart-content").offset().top; var gotox = basketx - productx; var gotoy = baskety - producty; var newimagewidth = $("#cart-image-1473").width() / 3; var newimageheight = $("#cart-image-1473").height() / 3; $("#wrapper").html(""); $("#wrapper").css({"position":"absolute","top": producty,"left": productx}); $("#cart-image-1473").clone() .prependto("#wrapper") .css({"position" : "absolute", "border" : "1px dashed black"}) .animate({opacity: 0.6}) .animate({opacity: 0.0, marginleft: gotox, margintop: gotoy, width: newimagewidth, height: newimageheight}, 1200, function() { }); /* effect */ }); //click }); //ready </script> <script type="text/javascript"> $(document).ready(function() { $('.mycarousel').jcarousel(); }); </script>
i tried use $("formrandom1473").unbind();
problem still same.
did mean use $("#formrandom1473").unbind();
#
instead?
or, since stored jquery object earlier:
formrandom1473.unbind();
if unbind doesn't work you, try instead, move before $.ajax
:
formrandom1473.submit(function() { return false; });
also, check js console errors.
Comments
Post a Comment