Q: ajax second call: function is not a function error When I click #submit-login button first time. The ajax call is successful. However, on clicking the same button a second time, I am hit with the error:
Uncaught TypeError: userLogin is not a function
HTML:
            <input id="username" type="username" name="" placeholder="Username">
            <input id="password" type="password" name="" placeholder="Password"><br>
            <button type="button" class="btn btn-primary" id="submit-login"> Login</button>

JS File Linked to HTML Page
    $("#submit-login").on("click", function(){
    userLogin();
    });
function userLogin(){
    userLogin = $("#username").val();
    userPass = $("#password").val();
        $.ajax({
            type: 'POST',
            url: 'controllers/login.php',
            data: {
                'username': userLogin,
                'password' : userPass
            },
            success: function(responseText) {
                console.log(responseText);
            }
        });
};

PHP File
<?php
$savedUser = "irexjr";
$savedPass = "1234";

$request_user = $_POST['username'];
$request_password = $_POST['password'];

$loginsuccess = "";

if(($request_user == $savedUser) && ($request_password == $savedPass)){
    echo 1;
}
else{
    echo 0;
}
?>


A: Try following, variable defined are created in global scope and as pointed in comment it has same name as function and further they are not required it seems.
function userLogin(){

        $.ajax({
            type: 'POST',
            url: 'controllers/login.php',
            data: {
                'username': $("#username").val(),
                'password' : $("#password").val()
            },
            success: function(responseText) {
                console.log(responseText);
            }
        });
};


A: What the other commentators are trying to tell you is the following:
You declare a function userLogin() in global scope. Now you run the function and inside the function body you declare another variable userLogin without using var, let or const causing the variable to end up in global scope as well overwriting the one already there -> the function. So you have several options:


*

*rewrite the function as @TechBreak already proposed

*rename the function as @Thomas Charlesworth proposed

*declare the variables inside the function body using var, let or
const to put them in function scope


In any case: Never ever declare variables without var, let or const. Otherwise they will end up in global scope causing errors that might be difficult to track down.

A: The function userLogin() creates a global variable with the same name. After calling userLogin() it is no longer a function but a string (the username) 
As posted by @Andreas
Changed Function name to resolve.
