I have this:
$.ajax({
url: "blah.php?something",
dataType: "json"
....
success: function(x){
for(i in x.artists) {
addbutton.text(x.artists[i].name).click(function(){
load(x.artists[i].name)
});
}
});
It's for a music player, and this is a suggestions engine. It loads artist names through AJAX, in JSON format from the PHP file, as you can see.
The problem is with the click() function which is supposed to load songs related to that artist. When the function gets called (ie the button gets clicked), instead of passing the artist's name as a string to load(), it passes x.artists[i].name, which of course is invalid outside of the ajax success function.
How would I go about solving this?
Thanks, Fela