I have implemented javascript code that uses JSON to generate a timeline. The JSON is being created using json_builder and it contains only the current user's information. The JSON displays correctly when accessed directly through its URL, but when this URL is used in the JS code, it fails to find the data, causing the timeline to get stuck on the loading screen.
Is it possible that the JSON doesn't actually get generated when it is accessed by the javascript? How can I solve this issue so that the javascript can access the correct data? Interestingly, if I provide the javascript with a static JSON file to work with, it works perfectly fine.
I believe what I need to do is somehow store the JSON within a variable in the javascript code, which can then be used as the data source instead of relying on a URL. Alternatively, is there a way to execute the json_builder within a javascript function?
I'm relatively new to working with Rails, so any guidance on how to resolve this issue would be greatly appreciated. Thank you in advance for your help.
Javascript:
<script>
$(document).ready(function() {
createStoryJS({
type: 'timeline',
width: '800',
height: '600',
source: 'users/<%= current_user.id %>/events.json',
embed_id: 'my-timeline'
});
});
</script>