使用sea.js和CommonsMultipartFile没有执行callback 注:java后台方法执行成功!没有报错!

html页面
` seajs.use('dataquery/batchquery',function(m){
        $("#upload_excel").change(function(){
            new m("upload_excel",callback,"xlsx");
        });
    });`
     */
js
define(function (require, exports, module) {

    var File = function(container,callback,supportFormat){

        this.file = $("#"+container);
        this.onload = callback||null;
        this.format = supportFormat||"xls,xlsx";

        this.iframe = "";
        this.originName = ""; //初始文件名
        this.uploadName = ""; //上传后文件名

        this.check();
        this.upload();

    };

    File.prototype={

        upload:function(){
            var that = this ;
            var form = $("#form");
            that.iframe = form.attr("target");
            form.attr("action",SGIS.API.getURL("common/upload"));
            SGIS.UI.addLoadingBar("上传中......");
            form.submit();
            /*var clear = function(){
                SGIS.UI.clearLoadingBar();
            };*/
            $("#"+that.iframe).one("load",function(){
                SGIS.UI.clearLoadingBar();
                var content = $(this).contents().find("body");
                var re = $.trim(content.text());
                if(re){
                    re = eval("("+re+")");
                    that.uploadName = re.fileName;
                    re.originName = that.originName;
                    that.onload&&that.onload(re);
                }
                content.empty();
            });
        },
        /**
         * 检验文件格式是否正确
         */
        check:function(){
            var path = this.file.val();
            if(!path){
                return false ;
            }
            var info = getFileInfo(path);
            this.originName = info.fileName ;
            var extendName =info.extendName.toUpperCase();
            var split = this.format.split(",");
            for(var i = 0;  i < split.length ; i++){
                if(extendName == split[i].toUpperCase()){
                    return true ;
                }
            }

            function getFileInfo(path){
                if(!path){
                    return null ;
                }
                var extendName =path.substring( path.lastIndexOf(".")+1);
                var fileName = path.substring(path.lastIndexOf("\\")+1) ;
                var json ={
                    extendName:extendName,
                    fileName :fileName
                };
                return json ;
            }

        },
        getFileName:function(){
            return this.uploadName;
        }
    };

    Object.defineProperty(File.prototype,"constructor",{
        enumerable:false,
        constructor:File
    });

    return File;
});
function callback(){
    if($("#upload_excel").val() == ""){
        alert("未选择Excel文件");
    }else{
        var address = $("#upload_excel").val();
        var body = $("#iframe").html();
        alert(address);
        alert(body);
        SGIS.API.get("batchQuery/analyExcel?address = "+address);
    }
};
阅读 2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题