How do I display JSON information on a webpage?

MarlonBerzamina

New Member
I have a Rails app that can render out a page with JSON information. I need to take the data from the JSON page and display it in a on a website I am building.the url for the information will be at \[code\]app.tricksgym.com/comments/random_comment.json\[/code\]I have it currently set up to only show \[code\]:comment\[/code\] and \[code\]:name\[/code\] in the json file.How do I access those two variables and display them in an html webpage?EDIT:Here is the JSON data I need displayed on the page:\[code\]{"comment":"This is a test comment.","name":"Tester T."}\[/code\]Here is my html code with the js in it that I have been able to come up with so far:\[code\]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Parent Comments</title><link href="http://stackoverflow.com/questions/13756754/_fonts/fonts.css" rel="stylesheet" type="text/css" /><link href="http://stackoverflow.com/questions/13756754/_css/style.css" rel="stylesheet" type="text/css" /><script type='text/javascript'> $(document).ready(function(){ $.getJSON("localhost:3000/comments/random_comment.json",function(data){ $.each(data, function(i,post){ var content = '<h3>' + post.comment + '</h3>'; $(content).appendTo("#CommentBox"); }); }); }); </script></head><body> <div id="CommentBox"> </div></body></html>\[/code\]But nothing is showing up on the page :( Please help me.
 
Back
Top