Getting JSON Array Object onto Javascript

Getting JSON Array Object onto Javascript

httpexhttpex 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...

Answers

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    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

  • httpexhttpex Posts: 7Questions: 2Answers: 0

    No, not using AJAX. Just pure javascript with Web Sockets. I just can't seem to get this to parse right with datatables unfortunately.

  • httpexhttpex Posts: 7Questions: 2Answers: 0

    I should add that the entire array gets written as a whole, to a div.

  • httpexhttpex Posts: 7Questions: 2Answers: 0

    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?

  • httpexhttpex Posts: 7Questions: 2Answers: 0

    I got it going and it's awesome! You guys seriously rock! Thank you!

  • httpexhttpex Posts: 7Questions: 2Answers: 0

    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?

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    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() or rows.add().

    That can be used with any data source, WebSockets or anything else that can be called in Javascript.

    Allan

This discussion has been closed.