>- the dataType is "JSON", not "json". >(I pointed this out earlier in this thread)
I noticed what sneaks did, I also noticed you had pointed it out, which is why my comment was in direct reply to sneaks post about the 'object side' and removing the quotes (check the quoted text in my post to see that it was for that post specifically) and was predicated on the assumption that he'd read and applied your suggestion. It was simply an FYI for him that that terminology ('object side') didn't make sense, and that the now-resolved object works perfectly fine with quotes on the name portion of the name-value pairs. I understand how jQuery handles the response, that's why I further indicated using the correct type in my follow up; I also understand that you can't eval an object. Neither of those have anything to do with my direct comment to sneaks. >OK. I think this clarifies that |json| is not an object, but a string. No, it clarifies that an ajax responseText formatted as JSON is a string, but that was never in question, as I've indicated above. As far as we're clarifying however: JSON isn't a string, it's text. The responseText from an ajax call is a string, and it may be in JSON format or it may not. If you want to quibble about whether the resolved object should then be called JSON that's fine, but also totally beside the point. On Apr 17, 12:56 am, dhtml <dhtmlkitc...@gmail.com> wrote: > 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