?
Solved

Microsoft AJAX, retrieve data every 3 minutes...

Posted on 2011-02-16
5
Medium Priority
?
935 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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
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…
Suggested Courses

752 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