1

I'm trying to find a solution to return data from ajax response with no possibility to execute a given callback function.

The following code is fix (third party api script) and the only thing i can control is the content of myfunction:

var myfunction( param ) {
   $.get( '/search', { q: param } );
   // no further ideas :D
   return; // <-- idealy the response of the ajax call
};

Promise.resolve()
   .then(
       function() {
           return myfunction( param );
       }
   ).then(
       function( res ) {
           return somefunction( res );
       }
   ).catch(
       function( res ) {
           return errorfunction( res );
       }
   );

The content of myfunction is by now a ajax call wich performs a database search.

Since I can't use a callback function I'm stuck there. I realy don't want to set the async option of $.ajax to false.

Any ideas?

Sarvan Kumar
  • 926
  • 1
  • 11
  • 27
Pascal C.
  • 11
  • 3
  • Did u check there ? https://stackoverflow.com/questions/5316697/jquery-return-data-after-ajax-call-success (second answer, with mutiple update) – Jax Teller Apr 05 '18 at 12:00
  • Thank you @JaxTeller ;-) I got the solution by returning just the ajax call. See my answer. – Pascal C. Apr 05 '18 at 12:07

1 Answers1

0

I got the solution. I only needed to return the ajax call.

var myfunction( param ) {
    return $.get( '/search', { q: param } );
};
Pascal C.
  • 11
  • 3