![]() |
Issue With Defining Object and appendChild
Okay so I am having a problem trying to initiate an AJAX request and, specifically, using the createElement and appendChild functions. More specifically I think the issue is that I don’t know how to properly define and set objects.
I want to initialize an object ‘comment’ that becomes a created element (of type div). Then I want to add innerHTML (as text from my AJAX responseText) and add an ID (again based on the responseText I get back). Then I am getting the div from the actual page (which will be ‘review_x’ where x is a number). At this point I want to append the text from the comment div to that original review_x div using appendChild. However, it is giving me the following error: Code:
Uncaught TypeError: Cannot call method 'appendChild' of undefinedCode:
function showComments(reviewId){For reference, here is the responseText (from the dev console in Chrome): Code:
1: {commentId:1, text:This is a comment, date_of_submission:2012-10-07 20:53:06, submitted_by_id:1,…} |
You should know that name is not advisable as an identifier for anything.
You should have tested that document.getElementById["review_" + commentResponse[i].review_id]} resolves to a DOM element, which it won't because you're calling a function using [] brackets. |
Nooooooooo way. Hahahahha it worked! Thanks a ton... that was such a rookie mistake I don't know how I didn't catch it before.
Good to know it was a syntax problem and not a logic or procedural issue. Again, thanks a ton! |
| All times are GMT +1. The time now is 09:59 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.