[英]The latest XML file-response from PHP is not getting loaded in Javascript
I am trying to visualize some data with the help of google charts. 我正在尝试借助Google图表可视化一些数据。 I have used AJAX-PHP call to retrieve data from the server.
我已经使用AJAX-PHP调用从服务器检索数据。 The PHP file is coded to write a XML file which in turn gets parsed and passed as data to google chart.
将PHP文件编码为编写XML文件,然后将其解析并作为数据传递到Google图表。 The problem that I am facing is, the chart is not getting refreshed however the XML file in the server is getting refreshed for every run.
我面临的问题是,图表没有刷新,但是每次运行都会刷新服务器中的XML文件。 But if I use debugger, everything is as expected.
但是,如果我使用调试器,一切都会如预期。 I know this is due to asynchronus call, but I could not resolve it.
我知道这是由于异步调用引起的,但是我无法解决它。 Even I tried with async = false but of no use.
即使我尝试了async = false,但没有用。
when extract button is pressed, the following function is called: 当按下提取按钮时,将调用以下功能:
function callforXML(FrDate, ToDate)
{
ajax_page = 'RetrieveData.php';
$.ajax({
type: "GET",
url: ajax_page,
cache: false,
dataType: "text/html",
data: "fdate=" + FrDate + "&tdate=" + ToDate,
success: loadXMLDocintoArray,
error: function(e)
{
alert("Connection to server is interrupted!");
}
});
}
function loadXMLDocintoArray()
{
var xmlhttp;
var x,xx,i;
var ondateXML, swiftXML, manualXML;
var appName = $("#applicationName :selected").text();
var selInterval = $("#interval :selected").text();
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
x=xmlhttp.responseXML.documentElement.getElementsByTagName("tcount");
var data = new google.visualization.DataTable();
// Declare columns
data.addColumn('string', 'Ticket Date');
data.addColumn('number', 'Swift');
data.addColumn('number', 'Manual');
for (i=0;i<x.length;i++)
{
xx=x[i].getElementsByTagName("ondate");
ondateXML = xx[0].firstChild.nodeValue;
xx=x[i].getElementsByTagName("scount");
swiftXML = xx[0].firstChild.nodeValue;
xx=x[i].getElementsByTagName("mcount");
manualXML = xx[0].firstChild.nodeValue;
data.addRows([[ondateXML,parseInt(swiftXML),parseInt(manualXML)]]);
}
var options = {
title: selInterval + ' Report for ' + appName,
width: 700,
height: 1200,
legend: { position: 'none' },
chart: { title: selInterval + ' Report for ' + appName,
subtitle: ' ' },
bars: 'vertical', // Required for Material Bar Charts.
axes: {
x: {
0: { side: 'top', label: ' '} }
},
bar: { groupWidth: "90%" },
animation:{
duration: 1000,
easing: 'out'}
};
var chart = new google.charts.Bar(document.getElementById('Chart_Div'));
chart.draw(data, options);
}
}
xmlhttp.open("GET","/XML/TicketCount.xml",false);
xmlhttp.send();
}
The success
callback function gets passed the returned data from the ajax call, which you are NOT passing along. success
回调函数将从ajax调用中传递返回的数据,而您并没有传递这些数据。
You probably want something more like 您可能想要更多类似的东西
success: function(xml) { loadXMLDocIntoArray(xml); }
function loadXMLDocIntoArray(xml) {
... do stuff with 'xml' argument
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.