On Apr 16, 5:14 pm, mkmanning <michaell...@gmail.com> wrote:
> As I said before: it's a string until it's eval'd, which happens with
> the 'json' response type within jQuery, or as I said you can eval the
Notice carefully what 'sneaks' used for his dataType:
jQuery.post(
"/wp/wp-admin/admin-ajax.php", {
action: "getProductInfo",
'cookie': encodeURIComponent(document.cookie),
'product_id': product_id
},function(obj) {
jQuery.each(obj, function(i, val) {
jQuery('#' + i).attr('value',val);
});
},"JSON");
}
- the dataType is "JSON", not "json".
(I pointed this out earlier in this thread)
So, the conditional below is false and following statement does not
execute:-
| [...]
| if ( type == "json" )
| data = window["eval"]("(" + data + ")");
| return data;
| },
What happens in this case is that jQuery.ajax does not handle a case
for dataType == "JSON" and passes the xhr's responseText through to
the callback function.
Identifier json holds a string value.
Sneaks resolved his issue by using eval directly, as:
var obj=eval('('+json+')');
If |json| is an object, that would be interpreted as:-
eval("([object Object])");
- which would result in EvalError.
OK. I think this clarifies that |json| is not an object, but a
string.
Garrett