Getting JSON Array Object onto Javascript
Getting JSON Array Object onto Javascript
httpex
Posts: 7Questions: 2Answers: 0
In each example for Arrays or Objects, you have them written out on the javascript file with the jQuery. How did those arrays or objects get on that javascript page? I'm trying to understand how my json data gets added to the js page that you're referencing in each example.
If I'm sending a web socket from the backend with my array of objects to the front end, am I writing it to file and then opening it? Sorry, not getting it...
This discussion has been closed.
Answers
Are you asking about the Ajax tab below the table, like in this example?
That is done by listening for the
xhr
event that DataTables emits and then reading the JSON data and dumping it onto the page.That is useful only for the examples though - the JSON data shown is purely just to let you see the structure for what has been loaded.
Allan
No, not using AJAX. Just pure javascript with Web Sockets. I just can't seem to get this to parse right with datatables unfortunately.
I should add that the entire array gets written as a whole, to a div.
I've decided to write to a json file and use ajax to open it. But my results are coming in vertically. Is that because the columns are too narrow or something?
I got it going and it's awesome! You guys seriously rock! Thank you!
Question: I have a web socket sending data from the back-end to my app.js file which then directs it to a div in my index.html page. When I point it to the div table "example", it doesn't populate the grid. I thought I read somewhere that it would work with Web Sockets. Is there another way I can get my Web Socket to populate the table?
We'd need to see either some code or the page, as at the moment I'm just guessing.
How are you attempting to add data tot he table? The correct way to do it would be with
row.add()
orrows.add()
.That can be used with any data source, WebSockets or anything else that can be called in Javascript.
Allan