jQuery逐步读取AJAX流? [英] jQuery read AJAX stream incrementally?

查看:156
本文介绍了jQuery逐步读取AJAX流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读这个问题但它没有'完全回答我的问题。
不幸的是,自从我上次查看AJAX以来,看起来XHR对象中的内容已经发生了变化,因此在它之前不再可能直接访问 responseText 完成填充。

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.

我必须编写一个使用AJAX的页面(最好是jQuery,但我愿意接受建议)从我拥有的服务器通过HTTP检索CSV数据无法控制。响应数据可能非常大;一兆字节的文本并不罕见。

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返回数据流?

The server is stream-friendly. Is there still any way to get access to a stream of data as it is being returned, directly from JavaScript?

我可以选择编写一些生活中的PHP代码在中间并使用某种Comet技术(长轮询,EventSource等),但我希望尽可能避免这种情况。

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.

如果它是相关的,假设这个问题,用户有最新版本的Firefox / Chrome / Opera和老浏览器兼容性不是问题。

推荐答案

你会想要直接使用javascript。原因是你想要不断轮询而不是等待回调。你不需要jQuery,这很简单。他们在Ajax Patterns网站上有一些这方面的优秀源代码

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流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆