Saturday, 28 September 2013

Cannot submit asp.net login form using $('form').submit();

Cannot submit asp.net login form using $('form').submit();

I have a function that 'pings' the server with a get request and if
successful submit the login form. However in setting the submit button to
return false, the form will not submit using $('form').submit(); The page
just seems to refresh, without actually logging the user in. Why is this?
<asp:Button ID="LoginButton" runat="server" CommandName="Login"
Text="Enter" ValidationGroup="LoginUserValidationGroup"
class="submitButton" />
submitButton.click(function () {
var url = 'https://examplesite.com/';
$.get(url).done(function () {
if (usernameBox.val() === '') {
usernameBox.attr('placeholder', 'Username Required');
passwordBox.attr('placeholder', '');
usernameBox.focus();
return false;
}
else if (passwordBox.length && passwordBox.val() === '') {
passwordBox.attr('placeholder', 'Password Required');
usernameBox.attr('placeholder', '');
passwordBox.focus();
return false;
}
else if (passwordBox.length && passwordBox.val().length <
6) {
passwordBox.focus();
return false;
}
else if (newPasswordBox.length &&
newPasswordBox.val().length < 6) {
passwordBox.focus();
return false;
}
else {
$('form').submit();
}
}).fail(function () {
errorMessage.text('Cannot Connect to Server - Please Try
Again Later').hide().fadeIn(350).delay(5000).fadeOut(350);
});
return false;
});

No comments:

Post a Comment