我不是开发人员,所以这是新的给我,但我是一个很长一段时间的系统管理员,请原谅我,如果我问愚蠢的问题!
基本上,我有一些解析XML和呼应PHP脚本是一个数字格式化为1 DP。
我使用一些JavaScript Wijmo部件,尤其是拨打该采取它的输入来自一个javascript变量。可以说,resultvalue。
我要填写结果值每隔5秒存在的/xmlparse.php我的PHP脚本的结果。该wijmo部件显然动态响应不断变化的变量,因此这将产生一个移动的针盘,而不必刷新整个页面。
我需要实现的是让这个JavaScript变量更新每隔5秒。
我已经在做与AJAX类似一个HTML页面,只需填充DIV与/xmlparse.php的结果,并使用所设置的时间间隔命令的伟大工程。
但我怎样才能让我的JavaScript变量更新,每5秒与脚本的结果?
一个例子将是一个很大的帮助!
code以下
问候 汤姆
解决方案 window.setInterval(函数(){
jQuery.ajax({
网址:'/ xmlparse.php
})。完成(功能(响应){
resultvalue =响应;
});
},5000);
您可能会需要解析的结果。也许XMLPARSE应json_en code画幅它让你的Ajax请求会抓住它作为一个对象。
编辑: 看你的源代码,我看到的径向计实际上并没有监控resultvalue变量检测时,它的改变。你必须自己更新。在这种情况下:
window.setInterval(函数(){
jQuery.ajax({
网址:'/ xmlparse.php
})。完成(功能(响应){
resultvalue =响应;
$(#规)wijradialgauge({值:resultvalue})。
});
},5000);
I am not a developer so this is new to me, but I am a long time sys admin so please forgive me if I am asking stupid questions!
Basically, I have a PHP script that parses some XML and echo's a single number formatted to 1 dp.
I am using some Javascript Wijmo widgets, in particular a dial that takes it input from a javascript variable. Lets say "resultvalue".
I want to populate "result value" every 5 seconds with the results of my php script that exists as /xmlparse.php. The wijmo widget apparently responds dynamically to a changing variable so this will produce a dial with a moving needle without having to refresh the whole page.
All I need to achieve is getting this javascript variable to update every 5 secs.
I am already doing something similar with AJAX on a html page by just populating a DIV with the results of /xmlparse.php and it works great using the set interval command.
But how can I get my javascript variable updating every 5 secs with the result of that script?
An example would be a great help!
Code Here
Regards Tom
解决方案window.setInterval(function(){
jQuery.ajax({
url:'/xmlparse.php'
}).done(function(response) {
resultvalue=response;
});
},5000);
You'll probably need to parse the result. Perhaps xmlparse should format it with json_encode so your ajax request could grab it as an object.
Edit: Looking at your source, I see that the radial gauge doesn't actually monitor the resultvalue variable to detect when it's changed. You'll have to update it yourself. In this case:
window.setInterval(function(){
jQuery.ajax({
url:'/xmlparse.php'
}).done(function(response) {
resultvalue=response;
$("#gauge").wijradialgauge({value:resultvalue});
});
},5000);