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); } Quote 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 (edited) 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); } Edited November 18, 2012 by chachew Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.