I have a form on my webpage and it uses JQuery Ajax. Now, when I press submit the first time, the code is executed and the data is submitted and the message appears. The problem is, if there is a message like "You cannot leave the field blank", and then I correct the details and press submit, the page reloads which should not happen. My JQuery -
$(document).ready(function () {
$('form').submit(function () {
$('#content').fadeOut(100, function () {
$(this).html('
<img src="//mywebsite.com/spinner.gif"/>
<div style="display:inline;color:#1FAEFF">Loading...</div>
').fadeIn(100);
});
$.get('submit.server', $(this).serialize(), function (data) {
$('#content').html(data);
});
return false;
});
});
I tried replacing the $('form').submit(function(){
to $('form').live('submit', function() {
but it doesn't work. Please Help! I am using the latest JQuery version from the website.
edit - I also tried on. The same thing Happens. Also, my form has multiple forms which are handled by this same script. One of my forms -
<form action="submit.server" method="GET">
<label for="form" style="color:#1FAEFF;">Change Your EmailAddr :
<br>
</label>
<div style="float:left;margin-top:20px">
<input type="email" class="forminput" name="gotemail" />
<br />
<input type="hidden" value="email" name="data" />
<button name="submit" value="email" class="action"
style="width:150px;height:70px">Submit</button>
</div>
</form>