I have read this question but it doesn't exactly answer my question. Unfortunately, it looks like things have changed in in the XHR object since I last looked at AJAX, so it is no longer possible to directly access responseText before it is finished being populated.

I have to write a page that uses AJAX (preferably jQuery, but I am open to suggestions) to retrieve CSV data via HTTP from a server I have no control over. The response data could be quite large; a megabyte of text is not uncommon.

服务器是流友好的.在返回数据流时,是否仍有直接从JavaScript访问数据流的方法?

I do have the option of writing some PHP code that lives in the middle and uses some sort of "Comet" tech (long-polling, EventSource, etc), but I would prefer to avoid that if possible.

In case it is relevant, assume for this question that users have the latest version of Firefox/Chrome/Opera and old browser compatibility is not an issue.

推荐答案

You're going to want to use straight up javascript for this. The reason is that you're going to want to continuously poll and not wait for the callbacks to fire. You don't need jQuery for this, it's pretty simple. They have some nice source code for this on the Ajax Patterns website.

Essentially, you'll just want to keep track of your last position in the response and periodically poll for more text past that location. The difference in your case is that you can subscribe to the complete event and stop your polling.

Jquery相关问答推荐

第一次单击后,Ajax addEventListener 停止工作

javascript 捕获浏览器快捷方式 (ctrl+t/n/w)

如果您的 Select 器对象无效,为什么 jQuery 不会炸弹?

bootstrap 模式中的自动完成问题

JSON字符串到JS对象

如何在jQuery中 Select 具有特定ID的所有元素?

在 Javascript 中,字典理解或 Object `map`

可以在删除类时反转css动画吗?

如何在 JQuery DataTable 中默认显示所有行

如何阻止 Chrome 进入调试模式?

jQuery:value.attr 不是函数

为什么不推荐$().ready(handler)?

测试空 jQuery Select 结果

Rails 无法正确解码来自 jQuery 的 JSON(数组变成带有整数键的散列)

如何让 JavaScript/jQuery Intellisense 在 Visual Studio 2008 中工作?

$(document).ready(function(){});页面底部的 vs 脚本

你如何记录jQuery中一个元素触发的所有事件?

表单 propType 失败:您在没有 `onChange` 处理程序的情况下向表单字段提供了 `value` props

删除所有以某个字符串开头的类

fancybox2 / fancybox 导致页面跳转到顶部