I had a problem today with eval()'ing the responseText after Ajax.Request. My problem was that my response was only text/javascript - an object in JSON: { // properties of object using JSON } I even haven't notice that the same code worked about a week, and everything was OK - no error, no exception. Until I added onException handler to Ajax.Request constructor - my application started to alerting users with errors. I have found that: - Prototype eval()s responseText automatically - when eval()'ing, JavaScript parser looks for a block of statements/ expressions (?) (eventually enclosed in curly braces {}) and it gets the object in JSON (surrounded in curly braces too) - in evalJSON() Prototype encloses the header string with ordinary braces () - the result of eval()'ing responseText isn't saved anywhere :-( - to get the object represented by my responseText JSON string, I have to eval() it again (ofc, enclosing in ordinary braces (), which I have done from the begin).
I have tought a lot about it and wasn't sure who blame for this exception, for necessity of eval()'ing twice excessively - me or the Prototype team. Now I think I should redesign my application and return the data using X-JSON headers rather than responseText. I only think it should be stated clearly in API Docs that evaling the responseText isn't identical to evaling the X-JSON headers and that the first one should be rather used for scripts to be executed (and not remebered) and the latter only for JSON. Or maybe it's a prototype design mistake - returning JSON with responseText is OK and it shouldn't be evaluated automagically but only on user demand. Or the other way round - it should be evaluated but saved. I'm not sure. Giving it under discussion :-) Thanks for the great work :-) DK --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---