Ik gebruik dit script: http://viima.github.io/jquery-comments/#link-3-4

Ik heb hier een test array van comments


var commentsArray = [  
{  
   "id": 1,
   "parent": null,
   "created": "2015-01-01",
   "modified": "2015-01-01",
   "content": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed posuere interdum sem. Quisque ligula eros ullamcorper quis, lacinia quis facilisis sed sapien. Mauris varius diam vitae arcu.",
   "pings": [],
   "creator": 6,
   "fullname": "Simon Powell",
   "profile_picture_url": "https://app.viima.com/static/media/user_profiles/user-icon.png",
   "created_by_admin": false,
   "created_by_current_user": false,
   "upvote_count": 0,
   "user_has_upvoted": false,
   "is_new": false
},
{  
   "id": 2,
   "parent": null,
   "created": "2015-01-02",
   "modified": "2015-01-02",
   "content": "Sed posuere interdum sem. Quisque ligula eros ullamcorper quis, lacinia quis facilisis sed sapien. Mauris varius diam vitae arcu.",
   "pings": [],
   "creator": 5,
   "fullname": "Administrator",
   "profile_picture_url": "https://app.viima.com/static/media/user_profiles/admin-user-icon.png",
   "created_by_admin": true,
   "created_by_current_user": false,
   "upvote_count": 2,
   "user_has_upvoted": false,
   "is_new": false
}


Dit probeer ik te krijgen met een ajax call vanuit mijn database:


				getComments: function(success, error) {
						$.ajax({
							type: 'get',
							dataType : 'json',
							url: '<?=HTML_ROOT?>inc/blog_comment.php?country=<?=$folder2?>',
							success: function(commentsArray) {
								console.log(commentsArray);
								success(commentsArray)
							},
							error: error
						});
					},


in blog_comments.php geeft ik dit terug:


 echo json_encode(array('id' => 3 , 'parent' => null, 'created' => '2015-01-03' , 'modified' => '2015-01-03', 'content' => '@Hank Smith sed posuere interdum sem.\nQuisque ligula eros ullamcorper https://www.google.com/ q' , 'fullname' => 'test' , 'profile_picture_url' => 'https://app.viima.com/static/media/user_profiles/user-icon.png'));




Ik krijg een error:

VM244743:296 Uncaught TypeError: commentsArray.map is not a function
at commentsFetched (eval at <anonymous> (jquery-1.12.4.min.js:2), <anonymous>:296:51)
at Object.success (indonesia:8082)
at i (jquery-1.12.4.min.js:2)
at Object.fireWith [as resolveWith] (jquery-1.12.4.min.js:2)
at y (jquery-1.12.4.min.js:4)
at XMLHttpRequest.c (jquery-1.12.4.min.js:4)


Hoe krijg ik de array exact zo terug?
Waarschijnlijk een conflict in naamgeving in de functie "success" op regel 8 in bovenstaande code? De success-functie verwacht in die context (of liever gezegd: scope) normaal gesproken een callbackfunctie, dezelfde die je gebruikt op regel 6. Waar zou (of is) een andere "success" functie binnen die zelfde context gedefinieerd moeten zijn?

Reageren