jquery - Page reloading on Ajax success -


i have form segmented 3 divs, displayed in an accordion style , submitted in ajax call, seems page reloading because displayed accordion divs hide following call. think have prevented default action correctly seems missing something.

//------------------ accordion ------------------------------------- $('.heading').on('click', 'img', function() {      var x = $(this).parent().next('div');     $(x).slidetoggle(function() {         if($(x).not(":hidden")) {             $(this).prev().find('img').attr('src','images/triangle_red_up.jpg');             }         if($(x).is(":hidden")) {                 $(this).prev().find('img').attr('src','images/triangle.jpg');                 }         });     });  ajax //------------------ form submit -----------------------------------         $('form').submit(function(e) {         e.preventdefault();      var datastring = $(this).serialize();      $.ajax({         type: "post",         url: "includes_php/pu_6.php",         data: datastring,         datatype: "json",         success: function(data) {             messages(data);         }         })      })  $('input#submit').click() { $('form').submit(); 

});

try this

    $('#submit').click() {             e.preventdefault();          var datastring = $('form').serialize();//if have form id use $('<frm id>').serialize()          $.ajax({             type: "post",             url: "includes_php/pu_6.php",             data: datastring,             datatype: "json",             success: function(data) {                 messages(data);             }            });  }); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -