Sim Posted May 15, 2020 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
Magictallguy Posted May 15, 2020 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
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.