javascript pass json to global variable

Solutions on MaxInterview for javascript pass json to global variable by the best coders in the world

showing results for - "javascript pass json to global variable"
Eric
23 Mar 2016
1//**
2//Remove the var keyword on global_datalength to make it global.
3//**
4//You can also use window.global_datalength.
5//**
6//Another way is to declare the variable outside the jQuery ready function.
7//**
8
9function leavereminder() {
10    $.ajax({
11        dataType: "json",
12        url: "<?=base_url()?>home/leavereminder",
13        async: false,
14        success: function(data) {
15            if(data.length != 0) {
16                for(x=0; x<data.length; x++) {
17                    var lblm = document.createElement('div');        
18                    lblm.innerHTML = '<label>'+data[x]+'</label>';  
19                    lblm.className = 'alert alert-info';                  
20                    document.getElementById('notifbody').appendChild(lblm);           
21                }
22            }
23            global_datalength = datalength;
24        },
25    });
26}
27
similar questions
queries leading to this page
javascript pass json to global variable