AJAX message could not be parsed

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

I ran into this while working with an UpdatePanel. After a partial postback, the returned AJAX would trip that Javascript error. The funny thing was that I was only tripping it in our staging environment, and not in my development environment. Any Googling you do on that error will likely not tell you much more than what is in the error message itself (or at least that’s what I found). Something funky happens on the way back to the client.

To debug, I opened up handy-dandy WinMerge and compared the response body from staging (broken) to the response body from my development environment (works). There were no significant differences, besides the difference in URL structures due to the difference in environments. However, I noticed that one of the URLs passed back were completely different – specifically, an AddThis script that was not being added via a ScriptManager.

We use a compressor on our staging and production servers to minify and compact CSS and Javascript. It’s an automatic process that happens behind the scenes that I don’t have to explicitly call or deal with. And that’s when I realized that the compressor was taking that AddThis script, doing its magic, and (probably) using Response.Write to inject the new JS URL into the response body. Sure enough, upon turning off staging’s compressor, everything worked fine, so I went back and added the AddThis script using document.write instead of just calling it directly, bypassing the compressor.

About Kelly Carter

I'm a freelance web developer, doing business under the name Rainworks Web Development. I'm a skeptical technophile, voracious reader, softcore gamer, and haphazard tinkerer. I have a long-term partner, a cat, and no time for glass ceilings.

Speak Your Mind

*