gpt4 book ai didi

c# - 提交到ashx时jquery文件上传错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:22:04 31 4
gpt4 key购买 nike

我正在尝试使用 Jquery file upload将文件异步上传到 C3 http 处理程序的插件。我已经完成了 GitHub site 上的设置步骤为项目。它似乎在 Firefox 中运行良好,但在 IE 中抛出 javascript 错误(“异常抛出且未被捕获”。第 95 行,字符 25,文件:test.html),即使文件已成功上传。我认为我的问题与我的 ashx 的响应有关。谁能看出我做错了什么?

这是我页面的 html 正文 (test.html):

<form id="file_upload" action="testupload.ashx" method="POST" enctype="multipart/form-data">
<input type="file" name="file" multiple>
<button>Upload</button>
<div>Upload files</div>
</form>
<table id="files"></table>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<script src="../Script/jquery.fileupload.js"></script>
<script src="../Script/jquery.fileupload-ui.js"></script>
<script>
/*global $ */
$(function () {
$('#file_upload').fileUploadUI({
uploadTable: $('#files'),
downloadTable: $('#files'),
buildUploadRow: function (files, index) {
return $('<tr><td>' + files[index].name + '<\/td>' +
'<td class="file_upload_progress"><div><\/div><\/td>' +
'<td class="file_upload_cancel">' +
'<button class="ui-state-default ui-corner-all" title="Cancel">' +
'<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
'<\/button><\/td><\/tr>');
},
buildDownloadRow: function (file) {
return $('<tr><td>' + file.name + '<\/td><\/tr>');
}
});
});
</script>

这是我的 ashx 中的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;


namespace Testing
{
/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
public class TestUpload : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
HttpPostedFile fileupload = context.Request.Files[0];


string strFileName = Path.GetFileName(fileupload.FileName);
string strExtension = Path.GetExtension(fileupload.FileName).ToLower();
string strSaveLocation = context.Server.MapPath("Upload") + "\\" + strFileName;
fileupload.SaveAs(strSaveLocation);

context.Response.ContentType = "text/plain";
context.Response.Write("{\"name\":\"" + fileupload.FileName + "\",\"type\":\"" + fileupload.ContentType + "\",\"size\":\"" + fileupload.ContentLength + "\"}");
}

public bool IsReusable
{
get
{
return true;
}
}
}
}

最佳答案

尝试改变:

context.Response.Write("{\"name\":\"" + fileupload.FileName + "\",\"type\":\"" + fileupload.ContentType + "\",\"size\":\"" + fileupload.ContentLength + "\"}");

对此:

context.Response.Write("{\"name\":\"" + fileupload.FileName + "\", type:\"" + fileupload.ContentType + "\",size:\"" + fileupload.ContentLength + "\"}");

您传回的对象只是格式错误。这应该可以解决问题。

关于c# - 提交到ashx时jquery文件上传错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5081119/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com