FreeASPupload与Ajax一起使用时无法正常工作

时间:2013-06-05 13:58:33

标签: html asp.net ajax asp-classic

我正在尝试使用'FreeASPUpload'控件(http://www.freeaspupload.net/)将文件上传到服务器 如果我在同一个文件中使用上传代码和HTML代码,它工作正常。

但我想编写如下代码。

当用户点击上传时,我正在调用一个Javascript函数,其中相应的ASP文件被称为

以下是我的上传代码。文件:GS_upload_files_Main.asp

<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{    
var xmlhttp;
 if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
 }
else
 {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
xmlhttp.onreadystatechange=function()
 {
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST","GS_upload_files.asp",true);
xmlhttp.send();
}
</script>
 </head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <body>
      <form name="frmSend" method="POST" data-ajax="false" enctype="multipart/form-data" accept-charset="utf-8">
      <input type="file" id="myfile" name="myfile" style ="WIDTH: 400px"> <!-- required> -->
       <div id="myDiv"><h2>Let AJAX change this text</h2></div>
        <input type=button id="Upload" name="Upload"  value="Upload" onclick="loadXMLDoc()"> 
     </form>
     </body>
    </html>

ASP文件:GS_upload_files.asp

<%@ Language=VBScript %>
<% 
option explicit 
Response.Expires = -1
Server.ScriptTimeout = 600
' All communication must be in UTF-8, including the response back from the request
Session.CodePage  = 65001
%>
<!-- #include file="freeaspupload.asp" -->
<%


  ' ****************************************************
  ' Change the value of the variable below to the pathname
  ' of a directory with write permissions, for example "C:\Inetpub\wwwroot"
  ' ****************************************************

  Dim uploadsDirVar
  uploadsDirVar = Server.MapPath("Signature_File")
%>  
<%
        function SaveFiles
    Dim Upload, fileName, fileSize, ks, i, fileKey

    Set Upload = New FreeASPUpload
    Upload.Save(uploadsDirVar)

    ' If something fails inside the script, but the exception is handled
    If Err.Number<>0 then Exit function

    SaveFiles = ""
    ks = Upload.UploadedFiles.keys
    if (UBound(ks) <> -1) then
        SaveFiles = "<B>Files uploaded:</B> "
        for each fileKey in Upload.UploadedFiles.keys
            SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" &     Upload.UploadedFiles(fileKey).Length & "B) "
        next
    else
        SaveFiles = "No file selected for upload or the file name specified in the upload form does not     correspond to a valid file in the system."
    end if
end function
%>
<%

            response.write SaveFiles()

%>

即使选择上传文件,所有时间都会给我以下消息。

“没有选择上传文件或上传表单中指定的文件名

请帮忙...

0 个答案:

没有答案