Ok, this is my first answer, but here it is.
I myself was punching my head over this problem and found out about it.
When you define a variable outside a function, it is automatically added to the 'window' object.
therefore, if we do this:
var myValue; function setValue() { myValue = "test"; }
So, if we use this knowledge to store $ .ajax data in a variable, it will look like this.
var xml; $.ajax({ type: "GET", url: "/?do=getcontentadm1n&category=homepage", dataType: "json", success : function(data) { window.xml = data; } }); alert(window.xml);
I think this will clarify a lot for many people and give you an answer. Thanks for reading my answer and source: http://snook.ca/archives/javascript/global_variable
EDIT: As mentioned in a comment below, this only works when async = false
.
source share