ajax.reload doesn't call the function defined in dataSrc

ajax.reload doesn't call the function defined in dataSrc

mj10clmj10cl Posts: 2Questions: 1Answers: 0

I have a data source on the server that's XML. When I do the initial load, the dataSrc function gets called to convert the XML to JSON. However, when I reload, the dataSrc function is not called again. The symptom is that the returned data set is reported to have syntax errors.

Example data source:

  <jobs name="this_job_name" jobdir="/path/to/jobs/this_job_name" jobid="318765" state="complete" result="pass" status="Correct state sequence detected">
</job>

DataTables call:

                var tableObject = $('#thetable').DataTable({
                  "ajax" : {
                    "url"       : file,
                    "dataType"  : "xml",
                    "cache"     : false,
                    "dataSrc" : function(xml) {
                      var json = new Array;

                      $(xml).find("jobs").each(function(index, element)
                      {
                        var job = new Object;

                        job.index = index;

                        var job_attributes = element.attributes;

                        for (var i = 0; i < job_attributes.length; i++)
                        {
                          job[job_attributes[i].nodeName] = job_attributes[i].nodeValue;
                        }

                        json.push(job);
                      });

                      return json;
                    },
                  },
                  columns : [
                    { data  : 'index' },
                    { data  : 'name' },
                    { data  : 'state' },
                    { data  : 'result' },
                    { data  : 'status' }
                  ]
                });

                window.setInterval(tableObject.ajax.reload(), 30000);

Error message:

SyntaxError: missing ] after element list[Learn More]
session_visualize.html:87:8
note: [ opened at line 87, column 0

How do I enforce reload to call dataSrc again? Why wouldn't it be called again if it had to be called the first time.

-Matt

Answers

  • kthorngrenkthorngren Posts: 21,311Questions: 26Answers: 4,948

    The ajax.dataSrc is executed each time in this example:
    http://live.datatables.net/kubedage/1/edit

    I would suggest putting console log statements in your function to help debug. First to verify if its running every 30 seconds and next to monitor the data.

    Kevin

  • mj10clmj10cl Posts: 2Questions: 1Answers: 0

    The example as I have listed in the original post does not work, but interestingly it does work if I change the setInterval call to:

    window.setInterval(function() {
      tableObject.ajax.reload();
    }, 30000);
    

    Not sure why each call has different results... Thanks for the update Kevin.

    -Matt

This discussion has been closed.