Jump to content


Photo

Trouble Passing Json Object As Parameter

json parameter object

  • Please log in to reply
1 reply to this topic

#1 chachew

chachew

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 17 November 2012 - 01:38 AM

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("&nbsp;&nbsp;<span id='" + id + " 'onclick='DoSomething(id, pack);'>" + key + "</span>&nbsp;&nbsp;&nbsp;");
});
$('#breadcrumbs').append('</br></br>'); })
.success(function(){
$('#loader').hide();
});

function DoSomething(id, pack){
$.each(pack, function(stage, items){
alert(stage);
});
$('#packages').html('&rarr;&nbsp;&nbsp;' + id);
}


#2 chachew

chachew

    Newbie

  • New Members
  • Pip
  • 6 posts

Posted 17 November 2012 - 11:03 PM

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 by chachew, 17 November 2012 - 11:03 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com