Solved

Add two function in Sys.Application.add_load?

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

688 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