I need to make this data
variable global:
$.ajax({
url: "get_data.php",
cache: false,
dataType: 'json',
data: {},
success: function(data) {
for(var i = 0; i < data.results.length; i++) {
if(my_data.hasOwnProperty(data.results[i].id)) {
my_data[data.results[i].id].name = data.results[i].name;
}
}
});
I want to have this globally declared. Do I need to declare it as array?
Set a variable equal to what you wish
data
to be equal to. And when givingdata
its value, reference the variable. Like this:Any variable can be "made global" by attaching it as a property of the window.
You can now access
data
as a global variable.