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