I'm sending out AJAX request for a XML file to plot a chart. The problem is everytime the response comes back, the chart refresh itself, even if the XML is exactly the same.
我发送了一个XML文件的AJAX请求来绘制图表。问题是每当响应返回时,图表刷新本身,即使XML完全相同。
I would like to use Javascript to check the content of the reponse XML with the cached XML, and only push to the chart if there are changes, dont do anything if it's the same.
我想用Javascript用缓存的XML检查响应XML的内容,如果有变化则只推送到图表,如果相同则不做任何事情。
How do I retrieve the cached XML?
如何检索缓存的XML?
Thanks!
谢谢!
3 个解决方案
#1
1
Create some variable, for example xmlString
. When you request new data, check whether xmlString==response
. If yes, cancel. If not, save the response in xmlString
and process it.
创建一些变量,例如xmlString。请求新数据时,请检查xmlString == response。如果是,请取消。如果没有,请将响应保存在xmlString中并进行处理。
#2
0
The approach mentioned by thejh
is suited only if you have no control over the server code.
只有在您无法控制服务器代码时,thejh提到的方法才适用。
However if you are manning the server too, you need to ensure that the server keeps track of the changes in underlying information/parameters and sends the xml if and only if this data/parameter has changed. You'll save on network bandwidth and increase performance.
但是,如果您也在配置服务器,则需要确保服务器跟踪基础信息/参数的更改,并且当且仅当此数据/参数已更改时才发送xml。您将节省网络带宽并提高性能。
#3
0
Nevermind, i finally got it.
没关系,我终于明白了。
if (i != 0) // if not 1st run
currentXML = newXML;
newXML = xmlhttp.responseText;
i = 1;
if (newXML != currentXML) // if XML content changes
{
...plot the chart...
}
#1
1
Create some variable, for example xmlString
. When you request new data, check whether xmlString==response
. If yes, cancel. If not, save the response in xmlString
and process it.
创建一些变量,例如xmlString。请求新数据时,请检查xmlString == response。如果是,请取消。如果没有,请将响应保存在xmlString中并进行处理。
#2
0
The approach mentioned by thejh
is suited only if you have no control over the server code.
只有在您无法控制服务器代码时,thejh提到的方法才适用。
However if you are manning the server too, you need to ensure that the server keeps track of the changes in underlying information/parameters and sends the xml if and only if this data/parameter has changed. You'll save on network bandwidth and increase performance.
但是,如果您也在配置服务器,则需要确保服务器跟踪基础信息/参数的更改,并且当且仅当此数据/参数已更改时才发送xml。您将节省网络带宽并提高性能。
#3
0
Nevermind, i finally got it.
没关系,我终于明白了。
if (i != 0) // if not 1st run
currentXML = newXML;
newXML = xmlhttp.responseText;
i = 1;
if (newXML != currentXML) // if XML content changes
{
...plot the chart...
}