comment jquery script

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Daniel van Seggelen

Daniel van Seggelen

05/05/2017 02:43:19
Quote Anchor link
Ik gebruik dit script: http://viima.github.io/jquery-comments/#link-3-4

Ik heb hier een test array van comments

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
                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:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
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?
 
PHP hulp

PHP hulp

19/04/2024 03:41:53
 
Thomas van den Heuvel

Thomas van den Heuvel

05/05/2017 17:06:52
Quote Anchor link
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?
Gewijzigd op 05/05/2017 17:17:20 door Thomas van den Heuvel
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.