Solved

Multiple AJAX scripts/functions in one page only runs last function

Posted on 2007-11-26
2
203 Views
Last Modified: 2012-08-14
I've got a page with 3 divs that I need filled using AJAX.  So I've got 3 js functions to accomodate that.  This is how I've got the section of the page:

<div id="Sect1"></div>
<script type="text/javascript">loadSect1();</script>

<div id="Sect2"></div>
<script type="text/javascript">loadSect2();</script>

div id="Sect3"></div>
<script type="text/javascript">loadSect3();</script>

------------
The problem I'm having is that only the last javascript function seems to be executing.  If I re-order the divs with say, Sect1 being last, then that function runs fine, but none of the other 2.  I've included an onclick event on each of the divs and that works but I don't want users to have to click each section to load the data.

What am I missing here?

I thank you in advance.
0
Comment
Question by:leadwave
2 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 20352343
do you functions (loadSect1-3) all use the same function to to make the XmlHttpRequest? Then you most likely have one object which gets overwritten with each call.
You either need to make instanzes of each (xmlhttprequest-)object, or wait 'til the request finished ith a response.
0
 

Author Closing Comment

by:leadwave
ID: 31411026
Thank you.  I knew I was missing something.  I simply created a new instance of the object and everything works great.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

790 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