特别提示:本代码引用了化境ASP无组件代码
前端JS部分:
function upload(id){ $("#imgWait"+id+"").show(); var formData = new FormData(); formData.append("file", document.getElementById("file"+id+"").files[0]); //通过formData提交数据 $.ajax({ url: "upload.asp", type: "POST", data: formData, contentType: false, processData: false, success: function (data) { if(data.indexOf("usualtooltrue") >= 0 ) { var datas = data.split('usualtooltrue'); $("#list"+id+"").val(datas[1]); alert("上传成功!"); }else{ alert("上传失败!"); } $("#imgWait"+id+"").hide(); }, error: function () { alert("上传失败!"); $("#imgWait"+id+"").hide(); } }); }
后端部分:
Public Function CheckAndCreateFolder(FolderName) set fso=server.createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(FolderName)) then CheckAndCreateFolder="yes" else CheckAndCreateFolder="no" end if set fso=Nothing End Function filepath="upload/" set upload=new upload_5xsoft'此处引用化境无组件上传 set file=upload.file("file") if file.FileSize<>0 then fn=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&"."&file.FileExt file.saveas server.MapPath(filepath&fn) If CheckAndCreateFolder(filepath&fn)="yes" then response.Write"usualtooltrue"&filepath&fn&"" Else response.Write"usualtoolerror" End If else response.Write"usualtoolerror" end If