Solved

Microsoft AJAX, retrieve data every 3 minutes...

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
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…

792 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