Asynchronously invokes the backend API sequentially with the deferred of jquery

Source: Internet
Author: User

It took me two days to find a way.

By the way, the Django paging stuff is also familiar.

If we don't use the latest deferred, we used to be very difficult to read and long.

The following is not an optimized code encapsulation.

This parameter renders the global call with non-Var.

And added Ajax pre-processing and end processing. Let the page present the upgrade information for the user.

var_self = This; Promisea=$.ajax ({URL:' {% url ' cp-dir '%} ', type:' Post ', data:{tgt:tgt,}, DataType: ' JSON ', Beforesend:function() {$ (_self). attr (' Disabled ', ' true '); $ (_self). Append ("<i class= ' uk-icon-cog uk-icon-spin ' ></i>"); }, Error:function() {alert (' Error loading JSON document '); }, Success:function(JSON) {uikit.notify ("Cp-dir", {status: ' Info ', timeout:1000}); varJSON =eval (JSON); $.each (JSON,function(Index, item) {uikit.notify (Json[index], {status:' Info ', timeout:1000});                });            }            }); Promiseb= Promisea.then (function(){                return$.ajax ({URL:' {% url ' auto_deploy:cmd-run '%} ', type:' Post ', data:{tgt:tgt,}, DataType:' JSON ', Error:function() {alert (' Error loading JSON document '); }, Success:function(JSON) {uikit.notify ("Cmd-run", {status: ' Info ', timeout:1000}); varJSON =eval (JSON); $.each (JSON,function(Index, item) {uikit.notify (Json[index], {status:' Info ', timeout:1000});                    }); }, Complete:function() {$ (_self). Children (I). Remove (); $ (_self). Append ("<i class= ' Uk-icon-check ' ></i>")                    }                }); });

Asynchronously invokes the backend API sequentially with the deferred of jquery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.