?
Solved

Add two function in Sys.Application.add_load?

Posted on 2011-02-16
1
Medium Priority
?
1,016 Views
Last Modified: 2012-05-11
I have two javascript see below: the problem is the first js does not work while the second js works.
but if I did not reference the second js the first js works...

i think the problem is on the Sys.Application.add_load(), how can I add multiple functions in it?
function onMessageLoad() {
    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(onMessageLoad);

Open in new window

unction initialize() {
    IfYouWantToStopItWithClearInterval = setInterval("onAjaxLoad('xml/performanceFactorMessage.xml')", 5000);
    onAjaxLoad('xml/performanceFactorMessage.xml');
}

function onAjaxLoad(file) {
    var req = new Sys.Net.WebRequest();
    req.set_url(file);
    req.add_completed(ajaxDataCallBack);
    req.invoke();
}

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

Sys.Application.add_load(initialize);

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
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 34913100
you've function with the same name, you should rename them :
function ajaxDataCallBack_1(response) { 

Open in new window

and update onMessageLoad line 4 :
req.add_completed(ajaxDataCallBack_1);

Open in new window


And :
function ajaxDataCallBack_2(response) {

Open in new window

so update onAjaxLoad line 4 :
req.add_completed(ajaxDataCallBack_2);

Open in new window

0

Featured Post

Technology Partners: 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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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

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