Within my JS file, I encountered an issue when trying to call one function from another. Initially, I called the function with no arguments using only its name handleResponse
. However, when attempting to add arguments by changing the function signature, I did not receive the desired outcome. I then tried calling the function as handleResponse()
, but that also failed.
The question arises: Why am I unable to call my function using brackets or pass arguments?
Below are the functions:
function sendRequest()
{
var username = "";
var game_id = -1;
username = document.getElementById("username").value;
game_id = document.getElementById("game_id").value;
req.open('GET', 'check_for_opponent.php?username='+username+'&game_id='+game_id);
req.onreadystatechange = handleResponse(username, game_id); <--- THIS IS THE CALL
req.send(null);
}
Function Being Called (with changed irrelevant body):
function handleResponse(username, game_id) {
if(req.readyState == 4) {
// DO SOMETHING...
}
}