json.errors isn't an array, but an undefined object. You can't use it like an array and casting it to $A doesn't help either. Since the errors coming back originally were an array, you'd think this would work, but it doesn't.
The frustration is that the original code works when json.errors has values, but doesn't when it's empty. The code that creates the json: $json = array('errors' => $fp->getErrors()); $this->sendJson($json); Any thoughts on how we could evaluate json.errors when it's an empty representation( "{"errors":[]}")? MS on July 17, kangax said: >Looks like you're creating a hash from an array (json.errors). Hash >actually doesn't know that it's an array and happily iterates over its >properties. >You then end up with a hash that has properties/methods from >Array.prototype (since for/in shows prototype.js-defined >Array.prototype methods). >Remove hash and use a plain array (when iterating over json.errors) or >represent your errors as an object (which is the best way to hold key/ >value pairs anyway) >><[EMAIL PROTECTED]> wrote: >> Hi, >> I have this snippet of code that uses the $H to create hash out of my >> form errors. This works perfectly fine in prototype version 1.5 but >> when I upgraded to version 1.6 it failes to work when no errors occur. >> When I have no errors my reponse text is this "{"errors":[]}" but >> errors.size() is always greater than 0. SHould I be doing something >> different? >> onFormSuccess : function(transport) >> { >> var json = transport.responseText.evalJSON(true); >> var errors = $H(json.errors); >> if (errors.size() > 0) { >> this.form.down('.error').show(); >> errors.each(function(pair){ >> this.showError(pair.key, pair.value); >> }.bind(this)); >> } >> else{ >> this.form.submit(); >> } >> } --~--~---------~--~----~------------~-------~--~----~ 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 prototype-scriptaculous@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-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---