javascript - AJAX request results in 'undefined is not an object' error -
my function works correctly, in data correctly requested via ajax , displayed appropriate, following error being thrown:
typeerror: undefined not object (evaluating 'obj[i].title') my function follows:
function populatenews(obj) { var article = $('article p'); article.each(function(i) { $(this).html('<p>'+obj[i].title+'</p>'); }); } i'm failing understand how resolve error. populatenews(obj) being called deferred ajax request via .done(); have read similar posts allude potentially being issue, no answer seems fit particular scenario.
no need have for loop.... error means obj's length less length of article
function populatenews(obj) { var article = $('article p'); //no need have loop article.each(function (i) { //if obj[i] not there update empty content $(this).html('<p>' + (obj[i] ? obj[i].title : '') + '</p>'); }); }
Comments
Post a Comment