Jump to content

Trouble Passing Json Object As Parameter


chachew

Recommended Posts

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);
}

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);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.