I stucked a little bit in here>
My php script returns this JSON (in variable response) (encoded array with json_encode) :
{"1":{"id":"pvv001","tooltip":"tip1","link":"http:\/\/domain\/file1.html"},"2":{"id":"pvv002","tooltip":"tip2","link":"http:\/\/domain\/file2.html"}} I hope this is valid JSON object ...
Then here is JavaScript function which should get this string and process it - load to ELEMENT "id" a content of "link".
function jLinks(idchapter) { var url = 'ajax_loadlinks.php'; var data = { idchapter : idchapter }; $.post(url,data, function(response) { //$('#coursecontent').html(response); var obj = JSON.parse(response); for (var i=0; i<obj.length; i+1) { $('#'+obj[i].id).html('<a href="'+obj[i].link+'">link</a>'); } }); } It is not throwing any error in browser or console, but elements are not updated at all.
I quess my parsing and accessing data is wrong somehow, but I have no idea how to debug.
objisn't going to have alengthproperty, therefore your loop never runs.for (var i=0; i<obj.length; i++)in place offor (var i=0; i<obj.length; i+1)[]