开发者

Good examples of reading an XML feed every 10 min

I am looking for the best approach to update a website with live data every 10 minutes. I have been looking on the net, but cant really find a sample.

This is just a hypothetical situation for me. If I want to get live data from somebody and put it in my website what would the best way to do it?

An easy exa开发者_运维知识库mple is a sports score website that gets the scores data from some where else that provides live sports scores and your site displays live sports score changes.


In JavaScript, you can probably do something like this (it's untested), but every 10 minutes you do a HEAD-request against the server, if the content of the XML-file is modified do a GET-request and process the data.

(function loop(){
    setTimeout(function(){
        $.ajax({
            type: "HEAD",
            url: "/whatever"
            success: function(xhr, data){
                if(xhr.status === 304) {
                    loop();
                }
                else {
                    $.ajax({
                        type: "GET",
                        url: "/whatever",
                        success: function(data){
                            // Process XML

                            // Run this function again.
                            loop();
                        }
                    });
                }
            }
        })
    // Run this every 10 min.
    }, 600000);
})();


If the XML file is local, perhaps this approach would be best:

something like INotifyCollectionChanged fires on xml file changed

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜