Berry
Berry

Reputation: 1749

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 onSuccess handler processes the data.

Anyone know what's going on here before I dig into the code?

Upvotes: 0

Views: 459

Answers (2)

Berry
Berry

Reputation: 1749

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.

Upvotes: 0

KooiInc
KooiInc

Reputation: 122936

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.

Upvotes: 1

Related Questions