Solved

Microsoft AJAX, retrieve data every 3 minutes...

Posted on 2011-02-16
5
906 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
  • 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now