开发者

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. 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. 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 onS开发者_如何转开发uccess handler processes the data.

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. What does it do? Why can't you use one callback and have it fired on readyState === 4? Furthermore you could try using the net panel of Firebug ('Net' tab on top) to see what takes all that time.


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. Switching to the more compact JSON representation instead of XML reduced the tedious XML parsing to, more or less:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜