【问题标题】:Valums file uploader xhr returns status 0, readystate 4 and responseText emptyValums 文件上传器 xhr 返回状态 0、就绪状态 4 和 responseText 为空
【发布时间】:2011-07-15 02:26:55
【问题描述】:

我在 asp.net Web 应用程序中使用 valums 文件上传器。它与实际上传一样工作正常。但是错误条件检查在 Chrome 和 FF 中无法正常工作。上传程序指向一个名为 fileupload.ashx 的处理程序,该处理程序检查是否已存在同名文件。 c#代码如下...

if (File.Exists(Path.Combine(path, fileName))) { returnJson = "{成功:假,错误:'重复文件名'}"; context.Response.ContentType = "文本/纯文本"; context.Response.Write(returnJson); 返回; }

我预计 result.error 属性中会出现上述错误消息。经过一些 javascript 调试后,我发现这段代码在 IE8 上运行良好,但在 Chrome 和 FF 中却不行。传输失败时,xhr responseText 包含空字符串。

来自 valums fileuploader.js 的 javascript sn-p 如下...

xhr.onreadystatechange = function() { 如果(xhr.readyState == 4){ self._onComplete(id, xhr); } };

令人惊讶的是,即使在 Chrome 和 FF 中上传成功时,responseText 也会正确返回。任何帮助将不胜感激。

【问题讨论】:

  • 假设您想一次上传单个文件,Ajax 控件工具包中的 AsyncFileUpload 控件对于 ASP.Net 来说可能是一个有用的替代方案。

标签: asp.net xmlhttprequest file-upload responsetext readystate


【解决方案1】:

我不太清楚为什么 fileupload.ashx 中有这段代码...

context.Response.ContentType = "text/plain";

这应该是……

context.Response.ContentType = "application/json";

因为返回值是 JSON 类型。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2017-10-09
    • 2011-03-05
    • 1970-01-01
    • 2020-09-13
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多