2009/10/1 Dave <[email protected]>:
>
> I have just upgraded to the latest scriptaculous (1.8.2) which
> includes prototype 1.6.0.3 and the following code no longer works:-
>
> Ajax.JSONResponse = function(xhr) {
> var data=eval('('+xhr.responseText+')');
> Object.extend(data,Enumerable);
> Object.extend(data,Hash);
> return data;
> };
>
> .......
>
> var opts = Ajax.JSONResponse(xhr);
> if (opts.size()>0) {
> opts.each(function(opt) {
> .....
>
> There is no error, it just seems that execution stops when trying to
> access any method of the opts object. I checked the response returned
> by Ajax in the previous and the latest versions, by doing console.log
> (data) after the eval, and they are identical. However, if I replace
> the eval line in the above code with this line
>
> var data=$H(eval('('+xhr.responseText+')'));
>
> it now works.
>
> I didn't write the original code and I am relatively new to prototype.
> Can anyone tell me whether the $H() is the correct solution or is
> there an alternative (better) solution.
>
> >
>
Did you know that the second parameter to onSuccess is the JSON object [1].
"Common callbacks
When used on individual instances, all callbacks (except onException)
are invoked with two parameters: the XMLHttpRequest object and the
result of evaluating the X-JSON response header, if any (can be
null)."
So, ...
onSuccess : function(xhr, json) {
// Use json.xxxx to access json's properties.
}
[1] http://api.prototypejs.org/ajax_section.html
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---