开发者

Export XML to local file using JavaScript

开发者 https://www.devze.com 2023-01-10 15:52 出处:网络
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 s

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 va开发者_开发技巧riable
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?


Download a file using Javascript

var url='http://server/folder/file.ext';    
window.open(url,'Download'); 
0

精彩评论

暂无评论...
验证码 换一张
取 消