Hello, my question today is about async ajax calls, I have simplified the situation as much as I could.
So, I have a region with two text items P54_ITEM1 and P54_ITEM2 and a button GO which when clicked calls "javascript:get_item1();get_item2();";
The region source contains the following javascript:
<script language="javascript">
<!--
/////////////////// first ajax call ////////////////////////////
function get_item1(){
var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=PROCESS1',0);
get.GetAsync(f_AsyncReturn_1);
get = null;
}
function f_AsyncReturn_1(){
if(p.readyState < 4){
document.getElementById('P54_LOADING_IMAGE').innerHTML = '<img src="&WORKSPACE_IMAGES.ajax_load.gif">';
}
else
if(p.readyState == 4){
process_response_1(p.responseText);
}
else{
return false;}
}
function process_response_1(gReturn){
var xmlDoc;
document.getElementById('P54_LOADING_IMAGE').innerHTML = '';
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(gReturn);
document.getElementById('P54_ITEM1').value = xmlDoc.documentElement.childNodes[0].text
}
/////////////////////////////////////////////////////////
//-->
</script>
<script language="javascript">
<!--
/////////////////// second ajax call ////////////////////////////
function get_item2(){
var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=PROCESS2',0);
get.GetAsync(f_AsyncReturn_2);
get = null;
}
function f_AsyncReturn_2(){
if(p.readyState < 4){
document.getElementById('P54_LOADING_IMAGE').innerHTML = '<img src="&WORKSPACE_IMAGES.ajax_load.gif">';
}
else
if(p.readyState == 4){
process_response_2(p.responseText);
}
else{
return false;}
}
function process_response_2(gReturn){
var xmlDoc;
document.getElementById('P54_LOADING_IMAGE').innerHTML = '';
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(gReturn);
document.getElementById('P54_ITEM2').value = xmlDoc.documentElement.childNodes[0].text
}
/////////////////////////////////////////////////////////
//-->
</script>
And then I have the two application processes respecively:
-- Process1
declare
xmldoc varchar2(4000);
begin
xmldoc := '<?xml version="1.0" encoding="UTF-8" ?>' || utl_tcp.crlf;
xmldoc := xmldoc || '<item>1</item>' || utl_tcp.crlf;
htp.p(xmldoc);
end;
Process2
declare
xmldoc varchar2(4000);
begin
xmldoc := '<?xml version="1.0" encoding="UTF-8" ?>' || utl_tcp.crlf;
xmldoc := xmldoc || '<item>2</item>' || utl_tcp.crlf;
htp.p(xmldoc);
end;
The question is how are these two calls executed? It seems like the second call always gets executed and the first one only once in awhile. P54_ITEM2 always gets value 2 where P54_ITEM1 either gets no value, or if it does, it's also 2 not 1.
What should I change so I have both calls executed properly (as I expect) every time?
Thank you for looking at this.
George