Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: n.map is not a functionn @ jquery-comments.min.js #74

Closed
KG20 opened this issue Oct 6, 2016 · 11 comments
Closed

Uncaught TypeError: n.map is not a functionn @ jquery-comments.min.js #74

KG20 opened this issue Oct 6, 2016 · 11 comments

Comments

@KG20
Copy link

KG20 commented Oct 6, 2016

Hello,

I am a novice to web development/js/jquery and I tried using the jquery-comments, I modified the getcomments function as follows:

getComments: function(success, error) { var comment_get_data = {'articleid':articleid, 'function':'getComments'}; $.ajax({ type: 'post', url: 'http://localhost/website/functions/comments.php', data: comment_get_data, success: function(commentsArray) { success(commentsArray) }, error: error }); },

and my comments.php has the following return functionality:

`case 'getComments':

        $data = mysqli_query($GLOBALS['connection'], "(SELECT comments.commentid, comments.parent, comments.created, comments.modified, comments.comment, comments.username, comments.createdByAdmin, comments.createdByCurrentUser, comments.upvoteCount, comments.userHasUpvoted, customers.cprofilePic AS profilePic FROM `comments` RIGHT JOIN customers ON customers.cusername=comments.username WHERE articleid = 1) UNION (SELECT comments.commentid, comments.parent, comments.created, comments.modified, comments.comment, comments.username, comments.createdByAdmin, comments.createdByCurrentUser, comments.upvoteCount, comments.userHasUpvoted, users.profilePic FROM `comments` RIGHT JOIN Users ON users.username=comments.username WHERE articleid = 1)");
        $i = 0;
        while($data2 = mysqli_fetch_assoc($data)){
            $commentsArray[$i] = $data2;
            $commentsArray[$i]['profileURL'] = "http://localhost/website/" . $data2['username'];
            $i++;
        }
        return $commentsArray;`

and I am getting the uncaught type error n.map is not a function, I am not sure what I am doing wrong, any help is appreciated. Thanks for the code and thanks in advance for your help!

@subodhcjoshi82
Copy link

Hi Can you please guide how you design the table and saving the data Are you using Mysql?

@KG20
Copy link
Author

KG20 commented Oct 7, 2016

Hi, yes I am using mysql... This is how my table looks:

mysql

@subodhcjoshi82
Copy link

Hmm according to me its not going to resolve the tree structure data as i read we have to use closure table ,to resolve the issue.I am not sure about your project structure so i cannt say more but for my project i am looking for closure table .

@KG20
Copy link
Author

KG20 commented Oct 7, 2016

Oh... just googled a bit about it, had no idea about this. Will look into this, thank you!

@KG20
Copy link
Author

KG20 commented Oct 8, 2016

May I also ask, should this table be called everytime a comment is posted or only when someone clicks on reply? Also, what is the role of this table in get function, because till now i have directly entered comments in database and called getfunction as above.

@subodhcjoshi82
Copy link

That what i want to discuss with you as you already developed thing in your application i am just starting my application to use it any how its these both table combination only will deliver the result and we have to use UNION ALL as per my R&D.

@KG20
Copy link
Author

KG20 commented Oct 8, 2016

oh ok... will further look into it!.. thanks

@KG20
Copy link
Author

KG20 commented Oct 9, 2016

Hi, just to let you know, I solved my problem and didn't need closure table, atleast not yet. I was not returning my post data properly. Although I am not sure how and where closure table will be used as in comment-data.js there seems to be just commentsArray, and although it does have a "parent" element it has nothing like depth/level. I am not sure if its being used. Anyways, if you figure out how to use it please let me know! Thanks for all your help!

@subodhcjoshi82
Copy link

But for long run where too many comment its cause slow DB and application but its ge8 your issue resolved

@KG20 KG20 closed this as completed Oct 9, 2016
@danman1234
Copy link

danman1234 commented May 5, 2017

With me it not works at all as well, i cant return an array from ajax, it gives me the error:
commentsArray.map is not a function

`
getComments: function(success, error) {
$.ajax({
type: 'get',

						url: '<?=HTML_ROOT?>inc/blog_comment.php?country=<?=$folder2?>',
						success: function(commentsArrays) {
							console.log(commentsArrays);
							success(commentsArrays)
						},
						error: error
					});
				},

`
I think this script is fully bugged
i also tried with json array, same thing

@KG20
Copy link
Author

KG20 commented May 17, 2017

Hi, I think its related to the data get comment has 2 retrieve.... Check if and when u r posting data it is being posted correctly or if u r using data directly it's in correct format..... I don't remember exactly but I think when I was using get without post and using data from sql there were some issues...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants