xxxxxxxxxx
The error message "Uncaught ReferenceError: function is not defined" typically occurs when you attempt to invoke or reference a function that has not been defined or is not accessible within the current scope!!
Also the error may occur if you try to call the function before it is defined. JavaScript code is executed sequentially, so if you try to call a function before it appears in the code, you will encounter a "function is not defined" error, therefore to resolve the error, you should ensure that the function is defined before attempting to call it
xxxxxxxxxx
// make sure you define the function before you call it.
function doAction() {
}
// Or using the arrow function syntax as follows:
const doAction = () => {
};
xxxxxxxxxx
// This is hard error to solve
// There are some cases
// 1. Your javascript code blocks have scope problem.
// 2. You may have syntax error like forget "," before Ajax request:
$.ajax({
url: requestUrl,
headers: { "token": token } // no comma error here
)}
// 3. In html tag `onClick` should change to id or class:
$(document).ready(function() {
$("Some id/class name").click(function(){
// your function can execute
});
});