我在 ASP.NET Web 应用程序中使用 valuefileuploader。它在实际上传中运行良好。但错误条件检查在 Chrome 和 FF 中无法正常工作。上传程序指向一个名为 fileupload.ashx 的处理程序,该处理程序检查同名文件是否已存在。下面给出了 C# 代码...
if (File.Exists(Path.Combine(path, fileName))) { returnJson = "{success:false, error:'Duplicate filename'}"; context.Response.ContentType = "text/plain"; context.Response.Write(returnJson); return; }
我预计 result.error 属性中会出现上述错误消息。经过一些 javascript 调试,我发现这段代码适用于 IE8,但不适用于 Chrome 和 FF。传输失败时,xhr responseText 包含空字符串。
下面给出了来自 valuems fileuploader.js 的 javascript 片段...
xhr.onreadystatechange = function() { if (xhr.readyState == 4) { self._onComplete(id, xhr); } };
令人惊讶的是,上传成功后,即使在 Chrome 和 FF 中,responseText 也能正常返回。任何帮助将不胜感激。
最佳答案
我不太确定为什么 fileupload.ashx 中有这段代码......
context.Response.ContentType = "text/plain";
这应该是...
context.Response.ContentType = "application/json";
因为返回值是JSON类型。
希望这有帮助。
关于asp.net - Valums 文件 uploader xhr 返回状态 0、readystate 4 和 responseText 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5300472/