2

I'm new to react.js.

I am following the documentation example on their website

I don't really understand this portion here:

// tutorial11.js ReactDOM.render( <CommentBox url="/api/comments" />, document.getElementById('content') ); 

when I use this comments.json file here <CommentBox url="comments.json" pollInterval={200} />, it won't work. But if I rename comments.json file to comments.txt, it works perfect. I don't know what I am missing here. I hope somebody here can explain to me further how to use .json file.

7
  • the code is the same in their website. Commented Mar 10, 2016 at 9:17
  • I don't know what I am missing here - So we will try to find out, but without your code it will be more difficult Commented Mar 10, 2016 at 9:18
  • <CommentBox url="/api/comments" /> I only wan't to know why the url porperty won't work if I use .json file. Everything works fine if I use .txt file with the same json content. Commented Mar 10, 2016 at 9:19
  • What do you have inside componentDidMount method? Commented Mar 10, 2016 at 9:22
  • 1
    Let us continue this discussion in chat. Commented Mar 10, 2016 at 9:24

2 Answers 2

1

url for commentbox is just a property which can be access via "this.props.url", to get the comment.json data use the ajax request in the lifecycle function of react js such as "ComponentDidMount".

Sign up to request clarification or add additional context in comments.

1 Comment

yes I know, everything works fine if I use url="comments.txt", but won't work if I use url="comments.json". And I want to know why? Thank you for your time friend.
0

Thank you guys for helping, I got it working already using <CommentBox url="db.php" pollInterval={200} />.

The solution is just making the output as json.

Here is the datail

Hope this helps.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.