Valums 文件上传器 xhr 返回状态 0、readystate 4 和 responseText 为空
我在 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 也能正确返回。任何帮助将不胜感激。
I am using valums fileuploader in asp.net web application. It's working fine with the actual uploads as such. But the error condition checking is not working properly in Chrome and FF. The uploader points to a handler called fileupload.ashx which checks if a file with the same name already exists. The c# code is given below ...
if (File.Exists(Path.Combine(path, fileName))) { returnJson = "{success:false, error:'Duplicate filename'}"; context.Response.ContentType = "text/plain"; context.Response.Write(returnJson); return; }
I expected above error message in result.error property. After some javascript debugging, I found that this code works well for IE8 but not in Chrome and FF. The xhr responseText contains null string when the transfer fails.
The javascript snippet from valums fileuploader.js is given below ...
xhr.onreadystatechange = function() { if (xhr.readyState == 4) { self._onComplete(id, xhr); } };
Surprisingly, responseText is properly returned even in Chrome and FF when the upload succeeds. Any help will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定为什么 fileupload.ashx 中有这段代码......
这应该是......
因为返回值是 JSON 类型。
希望这有帮助。
I'm not quite sure why the fileupload.ashx has this code in it ...
this should be ...
since the return value is of type JSON.
hope this helps.