jQuery, jQuery Spy & JSON question (quick fix?)
Hi Everyone -
I just starting playing with jQuery over the last we days, after discovering jQuery Spy -
http://leftlogic.com/lounge/articles/jquery_spy2/
. Very fun stuff!
I can't figure out one thing though: I have a PHP script which generates JSON output like the following:
"records": [ { 'string': 'Test Content', 'num': '1' }, { 'string': 'Test Content', 'num':'2' } ]
In other words, the script spits out an object within an object. I can't seem to get that JSON output to work with Jquery Spy though - it doesn't seem to want to play nicely with objects embedded within objects. What am I doing wrong? See code below -
Thanks!
-
$(function() {
$('#spyContainer').spy({
'ajax': '/jquery_spy/out_json.php',
'push': custom_push });
});
function custom_push(response) {
eval("var json = " + response); // convert to JSON
// I'm being lazy here, but you get the idea:
// Build the HTML
var html = '<div style="display:none">'
html += '<span class="ctr">' + json.records.num;
html += '</span><span class="content">';
html += json.records.string + '</span></div>';
// Prepend the HTML inside the container
$('#' + this.id).prepend(html);
}