Sim Posted May 15, 2020 Share Posted May 15, 2020 Anyone know how to make this coffee not refresh the page? Code tags are not above me <script> $(document).ready(function() { $(function() { $( "#createDialog" ).dialog({ autoOpen: false, }); $( "#opener" ).click(function() { $( "#createDialog" ).dialog( "open" ); }); }); // process the form $('form').submit(function(event) { // get the form data var form = $('#ajaxItem'); var post_url = $(this).attr("action"); // process the form $.ajax({ type : 'POST', url : post_url, data : formData, dataType : 'json', encode : true }) return false; // stop the form refrshing event.preventDefault(); }); }); </script> 1 Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted May 15, 2020 Share Posted May 15, 2020 Move event.preventDefault(); above return false So this // process the form $('form').submit(function(event) { // get the form data var form = $('#ajaxItem'); var post_url = $(this).attr("action"); // process the form $.ajax({ type : 'POST', url : post_url, data : formData, dataType : 'json', encode : true }) return false; // stop the form refrshing event.preventDefault(); }); becomes this // process the form $('form').submit(function(event) { // stop the form refrshing event.preventDefault(); // get the form data var form = $('#ajaxItem'); var post_url = $(this).attr("action"); // process the form $.ajax({ type : 'POST', url : post_url, data : formData, dataType : 'json', encode : true }) return false; }); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.