javascript pass json to global variable
//**
//Remove the var keyword on global_datalength to make it global.
//**
//You can also use window.global_datalength.
//**
//Another way is to declare the variable outside the jQuery ready function.
//**
function leavereminder() {
$.ajax({
dataType: "json",
url: "<?=base_url()?>home/leavereminder",
async: false,
success: function(data) {
if(data.length != 0) {
for(x=0; x<data.length; x++) {
var lblm = document.createElement('div');
lblm.innerHTML = '<label>'+data[x]+'</label>';
lblm.className = 'alert alert-info';
document.getElementById('notifbody').appendChild(lblm);
}
}
global_datalength = datalength;
},
});
}