Hi Craig,

Sounds like a timing issue.

AJAX is an asynchronous process, your JavaScript will continue to run whilst
the AJAX call is in progress. It sounds like you are trying to process the
answer before the response has been returned from the server.

Adding the 'Alert' gives the AJAX process time to complete.

Usually, you would specify a call back function in your AJAX call. This call
back function is then executed when the AJAX call returns its values. I
think you need to investigate this call back process.

With AJAX there are often two call back functions. One function is called if
the AJAX process competes successfully, the other if the AJAX call fails.

Hope this helps
Syd


-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx] On
Behalf Of Craig Jacobsen
Sent: 14 July 2009 15:24
To: 'Web Enabling the AS400 / iSeries'
Subject: [WEB400] Waiting for Ajax call to fill global variable

I have a global javascript variable defined and am looping through a series
of rows to see if a box is clicked.
If the delete button is clicked, I see if the row clicked can be deleted
(not in a table) through an AJAX call and hold on to the
response by accumating the returning message into the global variable, then
alerting that it (may be more than 1) cannot be deleted.
Problem is, the global variable is full on the callback but when I return
after the callAjax, it's sometimes empty.
This usually happens after the first call and is usually successful after
that.
I have temporarily fixed this problem by putting an alert('getting info') to
the screen only when the global variable is empty.
I'm guessing this gives a wait for the global variable to fill.
I have tried a pause function but that doesn't always work, the alert always
does.
Has anyone else had this problem? If so, is there a more elegant way to fix
it?

Thanks in advance,

Craig

Craig Jacobsen
Sr P/A
URL Pharma
7722 Dungan Rd
Philadelphia, Pa 19111
215.697.1719


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.