I have been cracking my head over this. I have a form that I need to submit via jquery without reloading the page. ` Somehow , the form will not submit unless I remove the callback function. But I also need this callback function to prevent the form from reloading. Any idea please? Thanks
<form id="myForm" method="post" action="some.php">
<input type="file" name="filename" />
<input type="button" id="button" />
</form>
<script>
$(document).ready(function(){
$(document).on("click", "#button", function(){
//Perform some operations then submit the form
$("#myForm").submit(function(e){ //Somehow, this part of the code is not running unless
e.preventDefault(); // I remove the callback function
alert("form submitted!"); // I also need the callback function to prevent page reloading
});
});
});
</script>