简体   繁体   English

原型的Ajax请求为什么要花这么长时间处理?

[英]Why does prototype's Ajax request take so long to process?

I'm using prototype.js and its Ajax object to implement an interactve graph widget. 我正在使用prototype.js及其Ajax对象来实现一个interactiveve图形小部件。 I generate an XML query for the data the user wants, POST it to the server with an Ajax.request, and it seems to take forever with Firefox. 我为用户想要的数据生成一个XML查询,并使用Ajax.request将其发布到服务器,而Firefox似乎要花很多时间。 The Firebug console seems to show the POST finishes with 200 OK in about 700 ms, but the onInteractive() handler I installed (which prototype triggers when readyState == 3) fires multiple times over the next TWELVE SECONDS, and then my onSuccess handler processes the data. Firebug控制台似乎显示POST在大约700毫秒内以200 OK结束,但是我安装的onInteractive()处理程序(原型在readyState == 3时触发)在下一个TWELVE SECONDS上触发多次,然后我的onSuccess处理程序进行处理数据。

Anyone know what's going on here before I dig into the code? 在我深入研究代码之前,有人知道这里发生了什么吗?

With readyState 3, the XHR-request is still in process, so that may trigger your onInteractive handler multiple times. 使用readyState 3时,XHR请求仍在处理中,因此可能多次触发onInteractive处理程序。 What does it do? 它有什么作用? Why can't you use one callback and have it fired on readyState === 4 ? 为什么不能使用一个回调并在readyState === 4上触发它? Furthermore you could try using the net panel of Firebug ('Net' tab on top) to see what takes all that time. 此外,您可以尝试使用Firebug的网络面板(顶部的“网络”选项卡)查看这段时间所花费的时间。

It turns out that what was happening was that Firebug was showing the POST finishing when readystate was 4, but not reporting the whole transaction finished until my onSuccess handler had finished, and the with the megabyte of XML that was taking quite a while. 事实证明,发生的事情是Firebug在readystate为4时显示POST完成,但是直到我的onSuccess处理程序完成以及兆字节的XML需要花费相当长的时间才报告整个事务完成。 Switching to the more compact JSON representation instead of XML reduced the tedious XML parsing to, more or less: 切换到更紧凑的JSON表示形式而不是XML,或多或少减少了繁琐的XML解析:

eval(responseText); doGraph();

Thanks for the comments, guys, they weren't exactly what I needed but they pointed me in the right direction, and the feature is now working very slickly. 伙计们,感谢您的评论,它们并不是我所需要的,但他们为我指明了正确的方向,并且该功能现在运行非常流畅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM