1. 程式人生 > >ajax非同步上傳檔案完成後執行其他操作

ajax非同步上傳檔案完成後執行其他操作

var fileCount=檔案個數;//計數器

$.ajax({

            //寫死測試

            url: baseUrl + "/dfs/upload/plugins/fileproxy/fileproxy?type=upload&fileNameOrId=" + filename,

            type: "POST",

            data: file,

            contentType: false,

            async: false,

            processData: false,

            success: function (data) {

                fileCount--;

                var reg = new RegExp("<result>group1", "g"); //g,表示全部替換。

                var temp = data.replace(reg, "");

                var reg1 = new RegExp("</result>", "g"); //g,表示全部替換。

                var temp1 = temp.replace(reg1, "");

                var tempUrl = baseUrl + 'dfs/download/' + temp1;

                tempjson = {

                    upfile: tempUrl,

                    fileName: filename

                };

                urlList.push(tempjson);

                if (fileCount == 0) {

                    attaches_url = urlList;

                    var datas = {

                        attaches_url: attaches_url,

                        message_notice: message_notice,

                        notice_title: notice_title,

                        over_time: over_time,

                        pic_url: pic_url,

                        publish_position_all: publish_position_all,

                        publish_scope: publish_scope,

                        publish_scope_all: publish_scope_all,

                        publish_staff: publish_staff,

                        inner_experts: inner_experts,

                        inner_position: inner_position,

                        outer_experts: outer_experts,

                        outer_position: outer_position,

                        staff_id: staff_id,

                        stick_notice: stick_notice,

                        token: token,

                        tips: tips,

                        notice_content: notice_content

                    };

                    //console.log(JSON.stringify(datas));

                  //其他的操作

                    formData(datas, staff_id, token);

                }