I am having trubles getting a variable declared.
I have
function employees(){
//init employees...;
}
employees.prototype.getName=function(){
if(ajax.doingStuff){
return;
}
}
$(document).ready(function(){
var ajax=new ajaxCall();
var people=new employees();
$('#option').on('change', function(){
people.getName();
})
})
and when I click $('#option) button, I got
Uncaught ReferenceError: ajax is not defined
Can anyone help me to solve this problem? Thanks a lot!
Your variable
ajaxonly exists within the scope of the function passed in toready(). If you want to use it elsewhere, you’ll either have to pass a reference to that object (eg, pass inajaxas a parameter of thegetNamefunction), or move all code to the same scope.For example:
Could be moved to the global scope, or:
Could be moved into the ready function.