【发布时间】:2015-05-25 11:35:12
【问题描述】:
我正在使用来自 blueimp (https://blueimp.github.io/jQuery-File-Upload/) 的 jquery-file-upload。
我有 FileHandler.ashx 用于文件上传。
我无法从文件处理程序返回正确的响应。在 javascript 方面,它总是收到错误。请指导我。
// 文件处理程序 (FileHandler.ashx)
public void ProcessRequest(HttpContext context)
{
string fname = String.Empty;
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
fname = context.Server.MapPath("~/UserImageUploads/" + file.FileName);
file.SaveAs(fname);
}
}
context.Response.ContentType = "text/plain";
context.Response.Write(fname);
context.Response.StatusCode = 200;
}
// javascript部分:
$(function () {
'use strict';
// Change this to the location of your server-side upload handler:
var url = 'FileHandler.ashx';
$('#fileupload').fileupload({
url: url,
dataType: 'json',
done: function (e, data) {
},
fail: function (e, data) {
},
});
});
结果总是“失败”,永远不会“成功”。错误是SyntaxError: Unexpected token C。
这与我返回的响应有某种关系,它的格式不正确,但它应该是什么格式?
【问题讨论】:
标签: jquery .net file-upload webforms ashx