Solved

Add two function in Sys.Application.add_load?

Posted on 2011-02-16
1
932 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
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 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

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

749 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