gpt4 book ai didi

javascript - 如何将 ASP.NET 处理程序的 url 传递给 jquery fileupload?

转载 作者:行者123 更新时间:2023-11-30 16:13:02 25 4
gpt4 key购买 nike

我使用 JQuery 文件上传和 ASP.NET 4.0 Web 应用程序项目。

但我不知道如何传递我的 ASP.NET C# 处理程序 url...

我想知道如何正确写AjaxFileHandler的url?

我试过使 ASP.NET 处理程序“AjaxFileHandler.ashx”和“url: AjaxFileHandler.ashx”但是出现错误

POST http://localhost:5468/AjaxFileHandler.ashx 500 (Internal Server Error)

.

-Post.aspx-

<script type="text/javascript">
$(function () {
$('#fileupload').fileupload({
datatype: "json",
url: 'AjaxFileHandler.ashx',
limitConcurrentUploads: 1,
sequentialUpload: true,
maxChunkSize: 100000,
add: function (e, data) {
$('#filelistholder').removeClass('hide');
data.context = $('<div>').text(data.files[0].name).appendTo('#filelistholder');
$('</div> \
<div class="progress"> \
<div class="progress-bar" style="width: 0%;"></div> \
</div>').appendTo(data.context);
$('#btnUploadAll').click(function () {
data.submit();
});
},
done: function (e, data) {
data.context.text(data.files[0].name + ' (전송완료)');
$('</div> \
<div class="progress"> \
<div class="progress-bar" style="width: 100%"></div> \
</div>').appendTo(data.context);
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#overallbar').css('width', progress + '%');
},
progress: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
data.context.find('.progress-bar').css('width', progress + '%');
}
});
});

function updateContent() {
oEditors.getById["postContent"].exec("UPDATE_CONTENTS_FIELD", []);
}
</script>

-AjaxFileHandler.ashx-

using System;
using System.Web;
using System.IO;

public class AjaxFileHandler : IHttpHandler
{
#region IHttpHandler Members
public bool IsReusable { get { return true; }}

public void ProcessRequest(HttpContext context)
{
//write your handler implementation here.
if (context.Request.Files.Count > 0)
{
string path = context.Server.MapPath("/UploadedFiles/");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var file = context.Request.Files[0];
string fileName = Path.Combine(path, file.FileName);
file.SaveAs(fileName);
context.Response.ContentType = "text/plain";
context.Response.Write("<script>console.log('" + fileName + "');</script>");
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var result = new { name = file.FileName };
context.Response.Write(serializer.Serialize(result));
}
}
#endregion
}

最佳答案

您可以在您的项目中创建 AjaxFileHandler.ashx 处理程序并调用类似 url:"AjaxFileHandler.ashx"

的 url

您收到错误是因为您的项目中不存在这样的 url( http://localhost:5468/AjaxFileHandler )

关于javascript - 如何将 ASP.NET 处理程序的 url 传递给 jquery fileupload?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35939776/

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