views:

27

answers:

1

I have a Windows 7 Gadget that runs JavaScript locally. It sends arguments to a Perl script on the server that returns XML. The XML is just timestamps and raw data. I graph these results into a time series using Flot. The graphs are usually performance data (%CPU utilization, logical disk space, etc.) and I want to have the option to export the results locally as an XML file so the users can open them in excel and generate reports.

Here is a code sample:

var graphData = new Array();//Global variable
function sendQuery(){
  var host_name = $('#hostNameInput').val();

  $.ajax({
    type: "GET",
    url: "http://okcmondev102/cgi-bin/itor_PerfQuery.pl?",//+arguments        
    dataType: "XML",
    success: function(xml){
      var results = new Array();
      var counter = 0;

      var $xml = $.xmlDOM(xml);

      $xml.find('DATA').each(function(){
        results[counter] = new Array(2);
        results[counter][0] = $(this).find('TIMESTAMP').text();
        results[counter][1] = $(this).find('VALUE').text();
        counter++;
      });

      plotGraph(results, host_name);
     }//end Success

  });//end AJAX

}//end sendQuery

function plotGraph(results, host_name){

  graphData.push({label: host_name, data: results});

  plot = $.plot($("#resultsArea"),graphData, options);

}//end plotGraph

Any suggestions on how I could accomplish this?

A: 

http://stackoverflow.com/questions/349067/download-a-file-using-javascript

var url='http://server/folder/file.ext';    
window.open(url,'Download'); 
JKirchartz
I suppose that the file has to be generated on the server before being downloaded, correct?
Mark Cheek
I think if it returns a text/XML mime-type you won't have to make the code write a file. To change the mime-type you've gotta update the header information the server sends back.
JKirchartz