Does anyone have any examples of reading a yaml file through ajax?

Does anyone have any examples of reading a yaml file through ajax?

sams96sams96 Posts: 3Questions: 1Answers: 0

I've got this far but haven't managed to get it to work, any suggestions?

    $('#example').dataTable( {
      ajax: {
        url: 'example.yml',
        dataSrc: function (json) {return jsyaml.safeLoad(json.data);}
      }
    } );

Answers

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    I would start by adding a console log statement in the dataSrc function to see the results of jsyaml.safeLoad(json.data). Do the results create a supported data structure as documented here?
    https://datatables.net/manual/data/

    Do you get any alert messages or errors in the browser's console?

    Kevin

  • sams96sams96 Posts: 3Questions: 1Answers: 0

    Thanks for the response.

    No console.logs or window.alerts in the dataSrc function seem to do anything, even just using static strings.

    I get the warning 'This page uses the non standard property “zoom”. Consider using calc() in the relevant property values, or using “transform” along with “transform-origin: 0 0”.', but I'm fairly certain that's been appearing with everything I do (including when using a json file and it working as intended.

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    dataSrc function seem to do anything, even just using static strings.

    Not sure what you mean by "using static strings". I would verify that you are getting an ajax response using the browser's Developer Tools > Network. This technote provides steps to use the developer tools if you need.

    Kevin

  • sams96sams96 Posts: 3Questions: 1Answers: 0

    I mean if I put something along the lines of console.log("Here's a string") in the function. I've verified that the proper ajax response is happening.

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    edited December 2019

    I've verified that the proper ajax response is happening.

    What is in the response? Please post an example.

    Inside the dataSrc function what do you get if you use console.log(json)?

    What do you get with console.log(jsyaml.safeLoad(json.data))?

    Without seeing examples of what you are getting it will be impossible to help debug. Maybe you can post a link to your page so we can take a look.

    Kevin

This discussion has been closed.