0

Is there any way I can make my js function wait until the callback return value. I need this because the rest part of my js function have to use the returned value from the callback.

user5783530
  • 221
  • 1
  • 4
  • 16

2 Answers2

0

A lot of libraries or frameworks offer comfort callback value. Yoy can look for the Jquery promise, bluebird promise, angular promise.

If you do not want to use third party libs, you can implement them by yourself, using setInterval method.

Drag13
  • 5,859
  • 1
  • 18
  • 42
0

You can't make your function to wait until the callback return. What you can do is move the rest of your workflow to the success call back of the function.

I have put a sample code of Ajax call here.

    $.get( _RequestURL, function () {}).done(function (success) {
        //Put the rest of your workflow here.

    }).fail(function (err) {
        //Put the error handler methods here.

    });
Nitheesh
  • 19,238
  • 3
  • 22
  • 49