Solved

Add two function in Sys.Application.add_load?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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…

829 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