JS上传


//异步上传文件,成功时,执行SuccessDo并返回1;
//当失败时,返回JSON数据
// url:文件要上传的url
// fileId:要上传的文件名
// 当上传文件成功时,执行ScuccessDo Function
///
Ajax.FileUpload = function (url, fileId, SuccessDo) {
    var imageLoad;
    var imageLoadParent;
    var myform = document.createElement("form");
    myform.style.display = "none";
    myform.action = url;
    myform.enctype = "multipart/form-data";
    myform.method = "post";

    var is_chrome = /chrome/.test(navigator.userAgent.toLowerCase());
    if (is_chrome && document.getElementById(fileId).value == '')
        return; //Chrome bug onchange cancel
    if (document.all || is_chrome) {// IE 
        imageLoad = document.getElementById(fileId);
        imageLoadParent = document.getElementById(fileId).parentNode;
        myform.appendChild(imageLoad);
        document.body.appendChild(myform);
    }
    else { //FF
        imageLoad = document.getElementById(fileId).cloneNode(true);
        myform.appendChild(imageLoad);
        document.body.appendChild(myform);
    }
    $(myform).ajaxSubmit({
        success: function (responseText) {
            //这里请对应修改上传文件返回值,不要轻易把我删掉
            var res = responseText.split('|');
            alert(res[1]);
            if (res[0] == 1) {
                $(".k-close").click();
                $(".k-window,.k-overlay").remove();
                SuccessDo();
            }
        }
    });
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM