0

我基本上希望从 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>

图像上传器.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>
4

1 回答 1

0

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

其他选择也很少,

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

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

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

于 2011-10-07T18:35:24.447 回答