jQuery post big text data transfer (eventual load)

pew*_*ers 5 javascript ajax jquery

The problem:

I have a jquery ajax (post) based website, where the website doesn't refresh every time user navigates to another page. Which means I have to pull data with ajax and present it to the user. Now for pulling small text data, this system works great. However once the text data is huge (let's say over 200,000 words), the load time is quite high (especially for mobile users). What I mean to say is, ajax tries to load full text information and displays it after it is done loading all text. So the user has to wait quite a bit to get the information.

If you look at a different scenario, let's say wikipedia. There are big pages in wikipedia. However, a user doesn't feel he/she has to wait a lot because the page loads step by step (top to bottom). So even if the page is large, the user is already kept busy with some information. And while the user is processing those, rest of the page keeps loading.

Question:

So is it possible to display, via ajax, information on real time load? Meaning keep showing whatever is loaded and not wait for the full document to be loaded?

Jor*_*dan 1

Ajax (xmlhttprequest) 是 html5 中的一个非常好的功能,对于同样的事情,ajax 比套接字更好,我的意思是非持久连接,但一旦连接是持久的(对于 xmlhttprequest 是不可能的),套接字是最快

\n\n

最简单的方法是使用网络套接字socket.io,但你需要一个JavaScript服务器来使用这个库,并且有一个主机,你可以使用管理工具免费获得一个主机:heroku

\n\n

如果您不想将 JavaScript 服务器与socketme库一起使用,您可以使用 PHP 服务器,但它有点复杂。

\n\n

另外,你可以换个角度思考,你尝试发送大量数据。\n200 000 个字相当于 70ko(我尝试了 lorem ipsum),上传速度与数据和连接速度/ping 相关。您可以在发送之前以任何方式压缩数据并在服务器端解压缩。可能有上千种方法可以做到这一点,但我认为最简单的方法是找到一个JavaScript 库来压缩/解压缩数据,然后简单地使用 jquery ajax 发送压缩的内容。

\n\n

编辑 \xe2\x80\x94 21/03/14:

\n\n

我误解了这个问题,你想显示当前上传进度吗?\n是的,可以通过使用 onprogress 事件,在 jQuery 中你必须遵循这个简单的示例:jQuery ajax 进度

\n