0

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!

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Malasuerte94
  • 1,454
  • 3
  • 14
  • 18

0 Answers0