【问题标题】:ASP.NET JavaScript Ajax File UploadingASP.NET JavaScript Ajax 文件上传
【发布时间】:2011-10-07 18:22:09
【问题描述】:

我基本上是希望将 HTML 页面中的图像发布到 asp.net C# 页面,然后将这些数据发布到服务器。

我找到了很多企业级和 webform-y 解决方案,但还有其他方法可以避免使用 webforms 吗?我不是生成 HTML 的忠实粉丝。基本上,伪代码是这样的。

<script type="text/javascript">
window.onload = function() {
    button.onclick = function() {
        http = new XMLHttpRequest();
        url = "imageuploader.aspx";
        params = <dunno how to post file data. Help?>
        http.open("POST", url, true);
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http.onreadystatechange = function () {
                  Test a bunch of stuff to see if image has been uploaded or we're still working on it
            }
    }
 }
 </script>

imageuploader.aspx

<%@ Page language="C#" validateRequest=false %>
<script language="C#" runat="server">
    private void Page_Load (object sender, System.EventArgs e) {
         <no clue what to do here since I've never done file uploading before>
    }
<script>

【问题讨论】:

    标签: c# javascript asp.net ajax image-uploading


    【解决方案1】:

    首先,XMLHttpRequest 不支持文件上传。您可以使用jQuery Form Plugin,表单插件使用隐藏的 iframe 元素来帮助完成任务。这是一种常见的技术,但它具有固有的局限性。 iframe 元素用作表单提交操作的目标,这意味着将服务器响应写入 iframe。

    还有一些其他的选择,

    http://www.phpletter.com/Demo/AjaxFileUpload-Demo/

    http://pixelcone.com/jquery/ajax-file-upload-script/

    现在,在服务器端,Request.Files 让您可以访问数组集合中所有发布的文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-16
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 2011-01-26
      相关资源
      最近更新 更多