Solved

Microsoft AJAX, retrieve data every 3 minutes...

Posted on 2011-02-16
5
926 Views
Last Modified: 2012-06-21
Hi! I am using the below code to retrieve xml file, it works fine.

What I want to do is to refresh the message every 3 minutes, how will I do revise my code to  achieve my needs?

Any ideas?
function onAjaxLoad() {
    
    var req = new Sys.Net.WebRequest();
    req.set_url('xml/welcomeMessage.xml');
    req.add_completed(ajaxDataCallBack);
    req.invoke();
}

function ajaxDataCallBack(response) {
    //debugger;
    var content = $get('middleText');
    var xml = response.get_xml();
    if (xml == null)
        Sys.Debug.fail('Could not load the welcome message');
    var welcomeMessageNode = xml.getElementsByTagName('message');
    if (welcomeMessageNode.length > 0) {
        if (welcomeMessageNode[0].textContent) //check compatiblity...
            content.innerHTML = welcomeMessageNode[0].XMLContent // for firefox...
        else // for internet explorer...
            content.innerHTML = welcomeMessageNode[0].xml;
    }
}

Sys.Application.add_load(onAjaxLoad);

Open in new window

0
Comment
Question by:PagodNaUtak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34912682
What about :

var IfYouWantToStopItWithClearInterval = setInterval("onAjaxLoad()", 3 * 60 * 1000);

Open in new window


?
0
 
LVL 8

Author Comment

by:PagodNaUtak
ID: 34912694
Where do I place that?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34912706
don't forget the update on the last line :


function someinit() {
    var IfYouWantToStopItWithClearInterval = setInterval("onAjaxLoad()", 3 * 60 * 1000);
    onAjaxLoad();
}

function onAjaxLoad() {
    var req = new Sys.Net.WebRequest();
    req.set_url('xml/welcomeMessage.xml');
    req.add_completed(ajaxDataCallBack);
    req.invoke();
}

function ajaxDataCallBack(response) {
    //debugger;
    var content = $get('middleText');
    var xml = response.get_xml();
    if (xml == null)
        Sys.Debug.fail('Could not load the welcome message');
    var welcomeMessageNode = xml.getElementsByTagName('message');
    if (welcomeMessageNode.length > 0) {
        if (welcomeMessageNode[0].textContent) //check compatiblity...
            content.innerHTML = welcomeMessageNode[0].XMLContent // for firefox...
        else // for internet explorer...
            content.innerHTML = welcomeMessageNode[0].xml;
    }
}

Sys.Application.add_load(someinit);

Open in new window

0
 

Expert Comment

by:someOne2010
ID: 34912709
any where
you can add this code at the top or after Sys.Application.add_load(onAjaxLoad);
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34912720
small update :


var IfYouWantToStopItWithClearInterval; // global var

function someinit() {
    IfYouWantToStopItWithClearInterval = setInterval("onAjaxLoad()", 3 * 60 * 1000);
    onAjaxLoad();
}

function onAjaxLoad() {
    var req = new Sys.Net.WebRequest();
    req.set_url('xml/welcomeMessage.xml');
    req.add_completed(ajaxDataCallBack);
    req.invoke();
}

function ajaxDataCallBack(response) {
    //debugger;
    var content = $get('middleText');
    var xml = response.get_xml();
    if (xml == null)
        Sys.Debug.fail('Could not load the welcome message');
    var welcomeMessageNode = xml.getElementsByTagName('message');
    if (welcomeMessageNode.length > 0) {
        if (welcomeMessageNode[0].textContent) //check compatiblity...
            content.innerHTML = welcomeMessageNode[0].XMLContent // for firefox...
        else // for internet explorer...
            content.innerHTML = welcomeMessageNode[0].xml;
    }
}

Sys.Application.add_load(someinit);

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question