11.07.2015 Views

AJAX and PHP

AJAX and PHP

AJAX and PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7}{xmlHttp.onreadystatechange = h<strong>and</strong>leGettingResults;xmlHttp.open("GET", url, true);xmlHttp.send(null);}else// if the connection is busy, retry after 1 secondsetTimeout("ajaxRequest(url,callback)", 1000);// called when the state of the request changesfunction h<strong>and</strong>leGettingResults(){// move forward only if the transaction has completedif (xmlHttp.readyState == 4){// a HTTP status of 200 indicates the transaction completed// successfullyif (xmlHttp.status == 200){// execute the callback function, passing the server responseinnerCallback(xmlHttp.responseText)}else{// display error messagealert("Couldn't connect to server");}}}5. The bulk of the client-side work is done by RealTimeChart.js:// SVG namespacevar svgNS = "http://www.w3.org/2000/svg";// the SVG document h<strong>and</strong>lervar documentSVG = null;// will store the root element that groups all chart elementsvar chartGroup = null;// how often to request new data from server?var updateInterval = 1000;// coordinates (in pixels) used to translate the chartvar x = 50, y = 50;// chart's dimension (in pixels)var height = 300, width = 500;// chart's axis originvar xt1 = 0, yt1 = 0;// chart's axis maximum valuesvar xt2 = 50, yt2 = 100;// number of horizontal <strong>and</strong> vertical axis divisionsvar xDivisions = 10, yDivisions = 10;// default text width <strong>and</strong> height for initial display (recalculated// afterwards)var defaultTextWidth = 30, defaultTextHeight = 20;// will retain references to the chart units for recalculating positionsvar xIndexes = new Array(xDivisions + 1);var yIndexes = new Array(yDivisions + 1);// will store the text node that displays the selected chart nodevar currentNodeInfo;// retains the latest values generated by servervar lastX = -1, lastY = -1;// shared svg elementsvar chartGroup, dataGroup, dataPath;195

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!