Base solution for your next web application
Open Closed

Service Call From js synchronously #4290


User avatar
0
pankajmathur created

Hi,

I need to make the service method call synchronously. How can I do that? For example below code gets all the variants from ProductAppService. I want until this call completes, it should not execute the code below this.

One possible way that I know is using $.ajax where I can specify to make the call synchronous. But I was wondering, if there is way to make the call synchronously in below code.

//Get all the variants var _ProductService = abp.services.app.product; var ProductKey = $("#Id").val(); abp.ui.setBusy(); _ProductService.getVariants(ProductKey).done(function (result) { Variants = result; showVariants(); }).always(function () { abp.ui.clearBusy(); });

Regards, Mahendra


1 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Don't. Just chain the Promise.

    // Get all the variants
    var _ProductService = abp.services.app.product;
    var ProductKey = $("#Id").val();
    abp.ui.setBusy();
    var getAllTheVariants = _ProductService.getVariants(ProductKey).done(function (result) {
        Variants = result;
        showVariants();
    }).always(function () {
        abp.ui.clearBusy();
    });
    
    getAllTheVariants.then(function () {
        // Put "the code below this" that should not execute "until this call completes" here
    });