Solved

Add two function in Sys.Application.add_load?

Posted on 2011-02-16
1
846 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now