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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -