×

学习:循环调用 ajax - 响应成功后循环

作者:andy0012018.10.15来源:Web前端之家浏览:10520评论:0
关键词:ajax循环

循环调用 ajax - 响应成功后循环。

function sendAjaxAll(){
        var i=0;
        var form=$('#restore_repo_div');

        sendAjax();
        function sendAjax(){
        var othis=select.eq(i),
                file_name = othis.find(".file_name").text(),
                otd=othis.find(".operate_icon a"),
                url=otd.attr("data-url");
        if(i>=select.length){
                return false;
        }else{
                $.ajax({
                url: url,
                cache: 'false',
                async:false,
                success: function(data) {
                        i ++;
                        othis.remove();
                        if($("#trashInputsTr").children().length==0){
                        $(".select_all").removeClass("all_have").addClass("all_none");
                        $(".select_icon").prop("src","{{ MEDIA_URL }}images/checkbox.png");
                        }
                        if (i ==select.length){
                        feedback("全部恢复成功!", 'success');
                        }
                        sendAjax();
                },
                error:function(xhr, textStatus, errorThrown) {
                        if (xhr.responseText) {
                        feedback(file_name + jQuery.parseJSON(xhr.responseText).error, 'error');
                        } else {
                        feedback("{% trans "Failed. Please check the network." %}", 'error');
                        }
                }
                });
        }

        }
}
sendAjaxAll();

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/ajax235325235.html

网友评论文明上网理性发言 已有0人参与

发表评论: