I think I am handling this correctly.
It's due to the asychronous ajax call.
I am giving a list of approvers and checking to see if any may be deleted by
checking the PO header table.
The user checks the approver(s) the user wants to delete, then presses the
delete button.
If there is an entry in the PO header, then the approver cannot be deleted.
What I don't understand is why a wait doesn't work and the alert does.
I can't use the callback (which is always correct) simply because I may be
doing more than one check.
Making this synchronous is probably the answer, but it's almost done now, so
I would hate to add a lot of code.
I don't see a way of passing back parameters from the callback. I tried
global variables instead.
Here is the function to check:
Global variables:
var ChkDelMsg = "";
var DelMsg = "";
var ChkDelMsgO = "";
var CkOK = false;
var y = 0;
//,==========================
function ChkBox(type){
//,see if at least 1 checkbox selected
//,==========================
var e = 0;
lib = document.getElementById("LibInv").value
//,go through all selected to see if anything checked
for (y = 0; y < mainform.TotalRows.value; y++) {
if (eval("mainform.chk"+y+".checked")) {
e++;
//,if update, no need to go further
if (type =='U') {
break;
}
user = eval("mainform.Aprover"+y+".value");
//,see if it's ok to delete
var url = "/cgi/getvar.mbr/ChkDel";
url = url + "?user=" + user;
url = url + "&lib=" + lib;
DelMsg = "";
callAjax(url, callBackChkDel);
if (DelMsg == "") {
alert('Getting Info');
}
}
}
if (e == 0) {
alert("You must select at least one name to continue");
return false;
}
var pos=ChkDelMsgO.indexOf("UserID");
if (pos >= 0) {
alert(ChkDelMsgO);
return false;
}
return true;
}
//,--------------------------
function callBackChkDel(oXmlHttp) {
//,callback info for checking Deletes
//,--------------------------
//,hold on to the response from the server
DelMsg = oXmlHttp.responseText;
var pos=DelMsg.indexOf("UserID");
if (pos >= 0) {
ChkDelMsg = DelMsg.substring(pos);
ChkDelMsgO += ChkDelMsg;
CkOk = false;
eval("mainform.chk"+y+".checked=false");
eval("row"+y+".style.backgroundColor='aliceblue'");
}
}
-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx] On
Behalf Of Walden H. Leverich
Sent: Tuesday, July 14, 2009 11:03 AM
To: Web Enabling the AS400 / iSeries
Subject: Re: [WEB400] Waiting for Ajax call to fill global variable
Has anyone else had this problem?
If so, is there a more elegant way to fix it?
Depends on the problem. Can you post code? It sounds like you're not
handling the response correctly (in an onComplete callback) but it could be
something else too. You may also in this case want to look at "SJAX", that
is, making the Async calls synchronous. All the frameworks I've seen do
support an indication that the request to the server should be made
synchronously, so that may help too.
-Walden
--
Walden H Leverich III
Tech Software
(516) 627-3800 x3051
WaldenL@xxxxxxxxxxxxxxx
http://www.TechSoftInc.com
Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)
--
This is the Web Enabling the AS400 / iSeries (WEB400) mailing list To post a
message email: WEB400@xxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit:
http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/web400.
As an Amazon Associate we earn from qualifying purchases.