Monday, November 29, 2010

Using variable outside of ajax callback function

Programmer Question

What is the best to use global variables outside of a callback function?



    var icon; 
$(function(){

$.get('data.xml', function(xml){

icon = xml.documentElement.getElementsByTagName("icon");
//this outputs a value
console.log(icon);
});
//this is null
//How can this maintain the value set above?
console.log(icon);
});


Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails