简体   繁体   English

从jquery中的ajax调用中调用Javascript函数

[英]Calling Javascript function from ajax call in jquery

  $.ajax({
         type: "GET",
         url: "tmpdata.xml",
         dataType: "xml"
    }).done(function(xml){   
 // alert("Hello Yagya");
        file  = $(xml).find("segment[id="+metric+"][name="+segment+"]").text();
        alert("Calling tmp file function");
        tmp(file);
   }); 

//Consider metric and segment names are alraedy assigned //考虑指标和细分名称已分配

In above code I am trying to call javascript function after fetching filename from xml file, But It seems that due to asynchronous call, tmp function is not called and also unable to access file name outside ajax function, please help me to come out of this problem. 在上面的代码中,我试图从xml文件中获取文件名后调用javascript函数,但是似乎由于异步调用,tmp函数未被调用,并且也无法访问ajax函数之外的文件名,请帮我解决这个问题问题。

Try this 尝试这个

$.ajax({
     type: "GET",
     url: "tmpdata.xml",
     dataType: "xml",
     success:function(xml){   
    // alert("Hello Yagya");
    file  = $(xml).find("segment[id="+metric+"][name="+segment+"]").text();
    alert("Calling tmp file function");
    tmp(file);
   }
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM