jQuery return value of deferred.then success when in function -
i've written function want return results of successful deferred function. however, since value want returned in scope of donecallbacks
, runsearch()
function returns undefined when running console.log(runsearch())
. how can have containing function return returned value of successful deferred.then()
?
function runsearch(){ $.get( "search.php" ).then( function() { // want runsearch() return results of function }, function() { console.log( "$.get failed!" ); } ); }
edit: everyone. since goal user return value in function, included function in donecallbacks
.
function runsearch(){ $.get( "search.php" ).then( function() { var returnvalue = 'return value' function dosomethingwithreturn(returnvalue) { console.log(returnvalue); } dosomethingwithreturn(returnvalue); }, function() { console.log( "$.get failed!" ); } ); } runsearch(); // logs returnvalue console.
may not elegant solution, works situation.
you can't that.
instead, need return promise, make code calls function asynchronous, well.
for more information see my blog.
Comments
Post a Comment