0

I have an ajax library You can see the code here. I have another function what uses ajax function and needs to return what ajax function returns simply something like this

function returnMyData(){
var data;
    ajax.get("someDomain",function(err,dt){
    if(dt){data= dt}
    });
return data;
}

Here everything looks fine but javascript will return null because callback wont fetch the data yet due to multi thread nature of javascript. So my question how can i wait till data is fetched and return then i tried to use while but it freezes the browser or gives unresponsive script error.

Community
  • 1
  • 1
nikoss
  • 3,254
  • 2
  • 26
  • 40
  • Duplicate of http://stackoverflow.com/questions/6685249/jquery-performing-synchronous-ajax-requests – Sebastian Nette Jul 23 '15 at 12:29
  • if you just a bit check the code you will see there is nothing about jquery and i wanna use async code as sync @SebastianNette its not just ajax based and check my ajax library as well – nikoss Jul 23 '15 at 15:41

0 Answers0