On May 13, 1:29 pm, Peter Warnock <petewarn...@gmail.com> wrote:
> [ ] is an array literal, like { } is an object literal.
>
> var obj = json[0];
>
> You shouldn't useevalon JSON. If you specify 'json' as your return
> type, jQuery will safelyevalvalid JSON.
>
jQuery uses what ECMA 262 calls "indirect eval".
window["eval"](json);
| // Get the JavaScript object, if JSON is used.
| if ( type == "json" )
| data = window["eval"]("(" + data + ")");
ECMA 262 has something to say about indirect eval, too:
| If value of the eval property is used in any way other than
| a direct call (that is, other than by the explicit use of its
| name as an Identifier which is the MemberExpression in a
CallExpression), or if the
| eval property is assigned to, an EvalError exception may be thrown.
So it seems that using jQuery here would not be as safe as using a
direct call to eval (as sneaks code uses) because the jQuery approach
may legally result in EvalError.
Further improvements to the code would be to replace the jQuery.each
call and not use the query selector. This would have the effect of
making the program smaller and faster, having the side effect of
removing some dependencies on jQuery.
Garrett
> - pw
>
> On May 12, 9:05 pm, sneaks <deroacheee...@gmail.com> wrote:
>
>
>
> > hi, in firebug my callback data(object) is like so:
>
> > [{"product_brand":"Creative Recreation","product_name":"Cesario
> > Hi","product_slug":"CRM-CESAR-PRIME-
> > HI","product_active":"1","product_description":"mens- red"}]
>
> > i have never noticed the square brackets before ...
> > but when i attempt to use each to oterate through the obnject for
> > values... i get nothing:
>
> > var obj=eval('(' + json + ')');
> > console.log( obj );
> > jQuery.each(obj, function(i, val) {
> > if (i) {
> > alert(val);
> > jQuery('#'+i).append(val);
> > }
>
> > });
>
> > this has always worked fro me before and i am not doing anything
> > different this time... but i would appreciate any insight into what
> > may be happeneing here