Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8306469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:20:14+00:00 2026-06-08T18:20:14+00:00

I am building a comment object using Backbone.js. The URL in the collection returns

  • 0

I am building a comment object using Backbone.js.
The URL in the collection returns json that looks like this:

        {'type': 'comment', 
        'data': [{"body": "commment number 1!", 
                "create_dt": 1343166264000, 
                "comment_id": 1, "depth": 0, 
                "user": {"sid": "1", 
                    "uid": "1", 
                    "name": "Amie C", 
                    "level": "2"}, 
                "sid": 1
                }, 
                {"body": "commment number 1-1!", 
                "create_dt": 1343166361000, 
                "comment_id": 4, 
                "depth": 1, 
                "user": {"sid": "1", 
                        "uid": "1", 
                        "name": "lila M", 
                        "level": "2"}, 
                "sid": 1}
                }]
        }

The url works in the browser and I was able to see all my json coming back. However, the problem I am having is there is no data coming back when loading the comment.js. I would see a Get request that’s red yet said 200 OK and has no body in the response. Also my model’s lenth is 0.

Thanks much in advanced.

Here is comment.js:

    //default comment model
    var Comment = Backbone.Model.extend({
        defaults: {
            body: "",
            create_dt: null,
            comment_id: null,
            depth: null,
            user: null,
            sid: null
        }
    });

    //instaitiate a new comment
    var comment = new Comment;

    //default event view
    var CommentView = Backbone.View.extend({
        tagName: "li",
        className: "comment",
        initialize: function(){
            this.render();
        },
        render: function(){
            $(this.el).html(this.model.toJSON());
            return this;
        }
    });


    //default comments collection
    var Comments = Backbone.Collection.extend({
        model: Comment,
        initialize: function(){
        },
        url:"http://127.0.0.1/test/objects/json/comments.json",
        parse: function(resp) {
            return resp.data;
        }
    });

    //default eventsview for events collection's view
    var CommentsView = Backbone.View.extend({
        tagName: "ul",
        className:"comments",
        intialize: function(){
            this.render();
        },
        render: function(){
            _.each(this.collection.models, function(comment){
                //init the CommentView and passed in its model here
                var commentView = new CommentView({model: comment});
                $(this.el).prepend(commentView.render().el)
            }, this);

            return this;
        }
    });

    //instantiate new events collection
    var comments = new Comments;
    var commentsView = new CommentsView({collection: comments});


    //on the new events collection, we fetch the data from URL
    comments.fetch({
        error:function(response, xhr){
            console.log(response);
            console.log(xhr)
        },
        success:function(){
            console.log("success");
            $('.comments_container').html(commentsView.render().el);
        }
    });

And the html looks like this:

    <!DOCTYPE html>
    <head>
      <meta charset="utf-8">
        <title>Share</title>
        <link rel="stylesheet" href="share.css" type="text/css"/>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
        <script src="http://backbonejs.org/backbone-min.js"></script>​
        <script src="js/comment.js"></script>
    </head>
    <body>
        <div class="main_app">
            <div class="comments_container"></div>
        </div>
    </body>
    </html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:20:16+00:00Added an answer on June 8, 2026 at 6:20 pm

    The problem I think is here in CommentView:

        render: function(){
            $(this.el).html(this.model.toJSON());
            return this;
        }
    

    this.model.toJSON() does not return a string, so it won’t show when you place it directly into the html like that.

    Try this instead:

            $(this.el).html(JSON.stringify(this.model));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing a JSON response via $.ajax() and building a form from this object's
building a site using PHP and MySQL that needs to store a lot of
I'm building an app that notifies user when new ThreadedComments appear. For this I'm
Im building an automatic refreshing comment section for my website using jQuery .load. So
I finally got this to work using the javascriptserializer to deserialize the json content.
I am building a request in Flash that contains a JSON encoded Array of
I am building an in-line SQL query (no need to comment about this I
I am building a web service that exclusively uses JSON for its request and
Building a website that has English & Japanese speaking users, with the Japanese users
I'm reading a book (Rails 3 in Action) that's building a project management system

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.