not able to access variable outside $.ajax method

cancel
Showing results for 
Search instead for 
Did you mean: 
ayushi_agrahari
Active Member II

not able to access variable outside $.ajax method

   I  am following GitHub - zhihailiu/alfresco-folder-size: Alfresco folder size to calculate the folder size and its working    fine,that is the folder size is showing as a separate component alongwith the properties of the folder but now I also want    to show the size in the document library of the folder.the following link contains the code

https://pastebin.com/ShL9EgrX

   

   when I am trying to access the variable size outside the jsonGet method,it is showing undefined that is the default value    of size



but after searching on internet,I learned that jsonGet is asynchronous,so it is exceuted after the synchronous code.so,I replaced the jsonGet method with $.ajax method and set the async to false to make $.ajax synchronous and access the variable outside the jsonGet method.but,still the variables "size" is undefined.

any help would be greatly appreciated.I am trying dis from many days



2 Replies
kalpesh_c2
Senior Member

Re: not able to access variable outside $.ajax method

Hi, Ayushi Agrahatri

Please try by Initialize the variable size,

var size = 0;

If you are calling a printSize() function then you can pass your size variable in that function

printSize(size);

And you can get it in your function

function printSize(folderSize)
{
console.log(folderSize)
}‍‍‍‍

Thanks,

Kalpesh

ContCentric

ayushi_agrahari
Active Member II

Re: not able to access variable outside $.ajax method

Yupp thanks for dis but I am actually trying to execute the last html statement inside the printsize function so as to show the size of folder in document library but after a little testing,I get to know that html statement is executed properly if it remains only inside the renderer function and not in any other function(e.g. even not inside the printsize function)

How to execute that html statement with size having the value that is manipulated inside the ajax function rather than the default value.