The key is here:
$(function login() {
});
Remember that jQuery is not a different language - it's just javascript with some helper functions already defined. So you're calling the $()
function, and passing in a function as an argument. The fact that you're naming the function is irrelevant - it's still getting passed as a parameter to $()
.
When you call the $()
or jQuery()
function and pass in another function, it's a shortcut for defining a document-ready event handler. So your code is really the same as doing this:
$(document).ready(function() {
var formData = $('#login-form').serialize();
$("input").prop("disabled", true);
// the rest of your function here...
});
...which causes it to run on every page load.
If you're just defining a function that will be called later, there's no reason to wrap it in $()
. You can define your function like this instead:
function login() {
var formData = $('#login-form').serialize();
$("input").prop("disabled", true);
// the rest of your function here...
}