How to return a value from a function that calls $.getJSON?

后端 未结 3 1170
青春惊慌失措
青春惊慌失措 2020-12-01 15:02
function lookupRemote(searchTerm)
{
   var defaultReturnValue = 1010;
   var returnValue = defaultReturnValue;

   $.getJSON(remote, function(data)
   {
      if (da         


        
3条回答
  •  长情又很酷
    2020-12-01 15:48

    If you don't want to use asynchronous function, better use the following:

    function getValue(){
       var value= $.ajax({ 
          url: 'http://www.abc.com', 
          async: false
       }).responseText;
       return value;
    }
    

    This function waits until the value is returned from the server.

提交回复
热议问题