i have a function
function cauta_pe_google(numele) {
var result;
var ficus;
$.get(numele, function(data) {
parser = new DOMParser();
var doc = parser.parseFromString(data, "text/html");
var rezultlate_vo = doc.getElementsByClassName("product_img small_img")[0].getElementsByTagName("li")[0];
if(rezultlate_vo) {
try {
result = rezultlate_vo.getAttribute("img-src");
} catch (error){
alert(error);
}
} else {
result = "nimic";
}
}).done(function() {
ficus = result;
alert (ficus); //here it's ok i get the image
return ficus;
});
alert (ficus); //here i get undefined error
//return ficus;
}
I tried to get an image from a link, at the first alert(ficus) I get the image result fine (http://image.jpg) but on the return (second alert) i have an undefined result, how i can extract that variable to use it in other places? Not only in the get function? Thanks!