xxxxxxxxxx
/* joshiyogesh0333@gmail.com */
// when ever need to stop next exicution then call the below function
// for more sourch : https://github.com/joshiyogesh0333/opensourchcode
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
xxxxxxxxxx
//option A
$("form").submit(function(e){
e.preventDefault();
});
xxxxxxxxxx
$("form").on("submit", function (e) {
e.preventDefault();
alert('Ok');
$( this ).unbind( 'submit' ).submit(); // Release
});
xxxxxxxxxx
// BEST OPTION
JUST:
* delete the <button></button> in the friggin FORM and add <a></a> with the same style instead, THE FORM WONT BE SUBMITTED THIS WAY.
* REMOVE THE action="" and method="" tags, and replace them in JQUERY\JS fetch() or $.ajax() functions!
** VOILA **
//option B
$("form").submit(function(e){
e.preventDefault();
});
xxxxxxxxxx
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function() {
//option A
$("form").submit(function(e){
alert('submit intercepted');
e.preventDefault(e);
});
});
</script>
</head>
<body>
<form action="http://google.com" method="GET">
Search <input type='text' name='q' />
<input type='submit'/>
</form>
</body>
</html>