//異步上傳文件,成功時,執行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(); } } }); }