chachew Posted November 17, 2012 Share Posted November 17, 2012 I am not able to successfully pass a JSON object as a parameter, i get an uncaught referenceError..any ideas? $.getJSON('./getMe.php', function(data){ $.each(data, function(key, pack){ var id = key.toLowerCase().replace(" ", "_"); $('#breadcrumbs').append(" <span id='" + id + " 'onclick='DoSomething(id, pack);'>" + key + "</span> "); }); $('#breadcrumbs').append('</br></br>'); }) .success(function(){ $('#loader').hide(); }); function DoSomething(id, pack){ $.each(pack, function(stage, items){ alert(stage); }); $('#packages').html('→ ' + id); } Link to comment https://forums.phpfreaks.com/topic/270823-trouble-passing-json-object-as-parameter/ Share on other sites More sharing options...
chachew Posted November 18, 2012 Author Share Posted November 18, 2012 Answer: $.each(data, function(key, pack){ var id = key, clickLink = $('<span>' + key + '</span>') .attr({id: id}) .click(function() { doSomething(id, pack);}); $('#breadcrumbs').append(clickLink); }); var doSomething = function(id, pack) { alert(pack); } Link to comment https://forums.phpfreaks.com/topic/270823-trouble-passing-json-object-as-parameter/#findComment-1393342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.