I am currently facing difficulties parsing JSON data from my Rails server using Javascript. While I have a good amount of experience with Rails, I am fairly new to JS and keep encountering an unknown error.
It would be extremely helpful if someone could guide me in the right direction! https://i.sstatic.net/XdKD1.png
EDIT: Code added I am attempting to integrate React into my Rails application. However, whenever I try to parse the JSON data, it leads to server crashes. As a result, I resorted to debugging in the console where I encountered the same error.
Here is a snippet of my view:
<%= react_component "SongsContainer", { songsPath: songs_path } %>
Below is the React code snippet:
var SongsContainer = React.createClass({
componentWillMount(){
this.fetchSongs();
setInterval(this.fetchSongs, 1000);
},
fetchSongs() {
$.getJSON(
this.props.songsPath,
(data) => this.setState({songs: data});
);
},
getInitialState() {
return { songs: [] };
},
render() {
return <Songs songs={this.state.songs} />;
}
});
Moreover, the controller I am using is quite straightforward:
render :json => Song.first.to_json
EDIT: Error encountered while utilizing getJSON function: https://i.sstatic.net/Eb86V.png