IC SunsetThe developerWorks Connections platform will be sunset on December 31, 2019. On January 1, 2020, this community and its apps will no longer be available. More details available on our FAQ.
Topic
  • No replies
karimkhan
karimkhan
1 Post

Pinned topic How to get data from file lying on server using ajax request

‏2011-04-06T11:44:06Z |
Hi Every one ,
I have one script which is generating graph using the parameters given to it , here I am generating those parameter using Random() function.

I have one TEXT file on server, generated by sensor , which contains parameters like humidity , temparature...

I want those parameter to be read and using those parameter in given below script I want to draw graph ,

So In what manner I should make AJAX request to call the file and read parameters from and retrieve them here....??
Graph looks like given on this link : http://www.rgraph.net/docs/dynamic.html
SCRIPT :

"
<html>
<head>
<script src="../libraries/RGraph.common.core.js" ></script>
<script src="../libraries/RGraph.common.context.js" ></script>
<script src="../libraries/RGraph.line.js" ></script>
</head>
<body>


<canvas id="cvs" width="600" height="250" style="float: right">No canvas support</canvas>
<script>

window.onload = function (e)
{

d1 = [];
d2 = [];
+for (var i=0; i<200; +i) {
d1.push(null);
d2.push(null);
}

function getGraph(id, d1, d2)
{
var graph = new RGraph.Line(id, d1, d2);
graph.Set('chart.xticks', 100);
graph.Set('chart.gutter', 25);
graph.Set('chart.xticks', 25);

return graph;
}
function drawGraph ()
{
RGraph.Clear(document.getElementById("cvs"));

var graph = getGraph('cvs', d1, d2);
graph.Draw();

// Add some data to the data arrays
var r1 = RGraph.random(7, 20);
var r2 = RGraph.random(7, 10);
// HERE I SUPPOSE TO RETRIEVE R1 R2 FROM FILE RESIDING ON SERVER
d1.push(r1);
d2.push(r2);

if (d1.length > 200) {
d1 = RGraph.array_shift(d1);
d2 = RGraph.array_shift(d2);
}
}
drawGraph();
}
</script>

</body>
</html>
"