ajax - Interaction in a Dynamic action between javascript and plsql tasks -


i'm trying execute several pl/sql blocks in dynamic action, feedback end user modal dialog reporting current satus.

something like:

processing step 1...  /*run pl/sql code step 1*/  processing step 2...  /*run pl/sql code step 2*/ 

and on...

both, pl/sql , javascript code, run intended when combined them on dynamic action in sequence:

1 - execute javascript

2 - execute pl/sql block /* wait result option checked*/

3 - execute javascript

4 - execute pl/sql block

the status dialog not been shown, pl/sql blocks completed without problems.

i realize must related javascript not been multithreaded, i've moved pl/sql block application processes , run them ajax calls this:

function something(){     var get;     var result = 0;     updatestatus('running step1');     = new htmldb_get(null,$v('pflowid'),'application_process=p6_step_1',0);     result = get.get();     if(result > 0){         updatestatus('running step 2');         = new htmldb_get(null,$v('pflowid'),'application_process=p6_step_2',0);         result = get.get();     }     closestatusdialog(); } 

but still, before, processes run fine dialog doesn't appear. added settimeout function each call, this:

function something(){     var get;     var result = 0;     updatestatus('running step1');     = new htmldb_get(null,$v('pflowid'),'application_process=p6_step_1',0);     result = settimeout(get.get(),500);     if(result > 0){         updatestatus('running step 2');         = new htmldb_get(null,$v('pflowid'),'application_process=p6_step_2',0);         result = settimeout(get.get(),500);     }     closestatusdialog(); } 

but still nothing. can running needed?.

i've checked browser console , no exeptions been thrown, likewise pl/sql blocks.

i've solved it, although solution doesn't rely on dynamic actions, javascript , applicacion processes. i'm posting similar problem.

the htmldb_get javascript object oracle-apex wrapper xmlhttprequest ajax object. poorly documented though.

i've found copy of code (at bottom) , turns out has function called getasync allows pass function parameter asign onreadystatechange attribute on xmlhttprequest object, executed each time attribute readystate of underlying xmlhttprequest changes.

the function passed parameter can't have parameters on own definition.

so, instead of calling get() on htmldb_get object need call getasync(somefunction)

with solution in case:

function something(){     var get;     = new htmldb_get(null,$v('pflowid'),'application_process=p6_step_1',0);     get.getasync(somefunctionstep1); }  function somefunctionstep1(){     if(p.readystate == 0){ /*p underlying xmlhttprequest object*/         console.log("request not initialized");         updatestatus('running step 1');     } else if(p.readystate == 1){         console.log("server connection established");     } else if(p.readystate == 2){         console.log("request received");     } else if(p.readystate == 3){         console.log("processing request");     } else if(p.readystate == 4){         console.log("request finished , response ready");         callstep2();     } }  function callstep2(){     var get;     = new htmldb_get(null,$v('pflowid'),'application_process=p6_step_2',0);     get.getasync(somefunctionstep2); }  function somefunctionstep2(){     if(p.readystate == 0){         console.log("request not initialized");         updatestatus('running step 2');     } else if(p.readystate == 1){         console.log("server connection established");     } else if(p.readystate == 2){         console.log("request received");     } else if(p.readystate == 3){         console.log("processing request");     } else if(p.readystate == 4){         console.log("request finished , response ready");         closedialog();     } } 

here's htmldb_get definition, @ end getasync function

/*   str should in form of valid f?p= syntax */  function htmldb_get(obj,flow,req,page,instance,proc,querystring) {   //   // setup variables   //   this.obj      = $x(obj);                   // object put in partial page   this.proc     = proc != null ? proc  : 'wwv_flow.show'; // proc call    this.flow     = flow != null ? flow  : $x('pflowid').value;          // flowid   this.request  = req  != null ? req  : '';               // request    this.page     = page; // page   this.params   = '';   // holder params   this.response = '';   // holder response   this.base     = null; // holder fot base url   this.querystring = querystring!= null ? querystring : null ; // holder passing in f? syntax   this.syncmode     = false;   //   // declare methods   //    this.addparam     = htmldb_get_addparam;   this.add          = htmldb_get_additem;   this.getpartial   = htmldb_get_trimpartialpage;   this.getfull      = htmldb_get_fullreturn;   this.get          = htmldb_get_getdata;   this.url          = htmldb_get_geturl;   this.escape       = htmldb_get_escape;   this.clear        = htmldb_get_clear;   this.sync         = htmldb_get_sync;   this.setnode      = setnode;   this.replacenode  = replacenode   //   // setup base url   //    var u = window.location.href.indexof("?") > 0 ?              window.location.href.substring(0,window.location.href.indexof("?"))              : window.location.href;    this.base = u.substring(0,u.lastindexof("/"));     if ( this.proc == null || this.proc == "" )             this.proc = u.substring(u.lastindexof("/")+1);     this.base = this.base +"/" + this.proc;     //   // grab instance form page form      //   if ( instance == null || instance == "" ) {     var pageinstance = document.getelementbyid("pinstance");       if ( typeof(pageinstance) == 'object' ) {         this.instance = pageinstance.value;       }   } else {     this.instance = instance;   }     //   // finish setiing base url , params   //   if ( ! querystring ) {       this.addparam('p_request',     this.request) ;       this.addparam('p_instance',    this.instance);       this.addparam('p_flow_id',     this.flow);       this.addparam('p_flow_step_id',this.page);   }    function setnode(id) {     this.node = html_getelement(id);   }   function replacenode(newnode){       var i=0;       for(i=this.node.childnodes.length-1;i>=0;i--){         this.node.removechild(this.node.childnodes[i]);       }       this.node.appendchild(newnode);   } } function htmldb_get_sync(s){   this.syncmode=s; }  function htmldb_get_clear(val){   this.addparam('p_clear_cache',val); }  // // return querystring // function htmldb_get_geturl(){     return this.querystring == null ? this.base +'?'+ this.params : this.querystring; }  function htmldb_get_escape(val){     // force string      val = val + "";      val = val.replace(/\%/g, "%25");      val = val.replace(/\+/g, "%2b");      val = val.replace(/\ /g, "%20");      val = val.replace(/\./g, "%2e");      val = val.replace(/\*/g, "%2a");      val = val.replace(/\?/g, "%3f");      val = val.replace(/\\/g, "%5c");      val = val.replace(/\//g, "%2f");      val = val.replace(/\>/g, "%3e");      val = val.replace(/\</g, "%3c");      val = val.replace(/\{/g, "%7b");      val = val.replace(/\}/g, "%7d");      val = val.replace(/\~/g, "%7e");      val = val.replace(/\[/g, "%5b");      val = val.replace(/\]/g, "%5d");      val = val.replace(/\`/g, "%60");      val = val.replace(/\;/g, "%3b");      val = val.replace(/\?/g, "%3f");      val = val.replace(/\@/g, "%40");      val = val.replace(/\&/g, "%26");      val = val.replace(/\#/g, "%23");      val = val.replace(/\|/g, "%7c");      val = val.replace(/\^/g, "%5e");      val = val.replace(/\:/g, "%3a");      val = val.replace(/\=/g, "%3d");      val = val.replace(/\$/g, "%24");      //val = val.replace(/\"/g, "%22");     return val; }  // // simple function add name/value pairs url // function htmldb_get_addparam(name,val){     if ( this.params == '' )       this.params =  name + '='+ ( val != null ? this.escape(val)  : '' );   else      //this.params = this.params + '&'+ name + '='+ ( val != null ? val  : '' );      this.params = this.params + '&'+ name + '='+ ( val != null ? this.escape(val)  : '' );      return; }   // // simple function add name/value pairs url // function htmldb_get_additem(name,value){   this.addparam('p_arg_names',name);   this.addparam('p_arg_values',value);   }  // // funtion strips out ppr sections , returns // function htmldb_get_trimpartialpage(starttag,endtag,obj) {    settimeout(html_processing,1);    if (obj) {this.obj = $x(obj);}    if (!starttag){starttag = '<!--start-->'};      if (!endtag){endtag  = '<!--end-->'};    var start = this.response.indexof(starttag);    var part;    if ( start >0 ) {        this.response  = this.response.substring(start+starttag.length);        var end   = this.response.indexof(endtag);         this.response  = this.response.substring(0,end);    }                 if ( this.obj ) {           if(this.obj.nodename == 'input'){             if(document.all){               gresult = this.response;               gnode = this.obj;               var ie_hack = 'htmldb_get_writeresult()';               settimeout(ie_hack,100);             }else{               this.obj.value = this.response;             }           }else{             if(document.all){               gresult = this.response;               gnode = this.obj;               var ie_hack = 'htmldb_get_writeresult()';               settimeout(ie_hack,100);             }else{               this.obj.innerhtml = this.response;             }           }        }    //window.status = 'done'    settimeout(html_doneprocessing,1);    return this.response; }   var gresult = null; var gnode = null function htmldb_get_writeresult(){     if(gnode && ( gnode.nodename == 'input' || gnode.nodename == 'textarea')){     gnode.value = gresult;     }else{     gnode.innerhtml = gresult;     }     gresult = null;     gnode = null;   return; }  // // function return full response // function htmldb_get_fullreturn(obj) {    settimeout(html_processing,1);    if (obj) { this.obj = html_getelement(obj);}         if ( this.obj ) {           if(this.obj.nodename == 'input'){             this.obj.value = this.response;           }else{             if(document.all){               gresult = this.response;               gnode = this.obj;               var ie_hack = 'htmldb_get_writeresult()';               settimeout(ie_hack,10);             }else{               this.obj.innerhtml = this.response;             }           }        }        settimeout(html_doneprocessing,1);   return this.response; }  // // perform actual server // function htmldb_get_getdata(mode,starttag,endtag){    html_processing();    var p;    try {       p = new xmlhttprequest();     } catch (e) {       p = new activexobject("msxml2.xmlhttp");     }     try {         var starttime = new date();         p.open("post", this.base, this.syncmode);                    p.setrequestheader('content-type','application/x-www-form-urlencoded');         p.send(this.querystring == null ? this.params : this.querystring );         this.response = p.responsetext;         if ( this.node )           this.replacenode(p.responsexml);         if ( mode == null || mode =='ppr' ) {             return this.getpartial(starttag,endtag);         } if ( mode == "xml" ) {             settimeout(html_doneprocessing,1);             return p.responsexml;         } else {             return this.getfull();         }      } catch (e) {        settimeout(html_doneprocessing,1);        return;     }  }  function html_doneprocessing(){   document.body.style.cursor="default"; }  function html_processing(){     document.body.style.cursor="wait"; }  /*  adds better aysnc functionality  htmldb_get object  pvar function want call when xmlhttp state changes in function specified pvar xmlhttp object can referenced variable p */ htmldb_get.prototype.getasync = function(pvar){    try{       p = new xmlhttprequest();     }catch(e){       p = new activexobject("msxml2.xmlhttp");     }     try {         var starttime = new date();             p.open("post", this.base, true);             if(p) {                     p.onreadystatechange = pvar;                     p.setrequestheader('content-type','application/x-www-form-urlencoded');                     p.send(this.querystring == null ? this.params : this.querystring );                     return p;         }          }catch(e){       return false;     }  }     /* pdf output */ /*gets pdf src xml */    function htmldb_externalpost(pthis,pregion,pposturl){    var purl = 'f?p='+html_getelement('pflowid').value+':'+html_getelement('pflowstepid').value+':'+html_getelement('pinstance').value+':flow_fop_output_r'+pregion    document.body.innerhtml = document.body.innerhtml + '<div style="display:none;" id="dbasesecondform"><form id="xmlformpost" action="' + pposturl + '?ie=.pdf" method="post" target="pdf"><textarea name="vxml" id="vxml" style="width:500px;height:500px;"></textarea></form></div>';    var l_el = html_getelement('vxml');    var = new htmldb_get(l_el,null,null,null,null,'f',purl.substring(2));    get.get();    = null;    settimeout('html_getelement("xmlformpost").submit()',10);   return; }   function $xml_control(pthis){         this.xsl_string = '<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"><xsl:output method="html"/><xsl:param name="xpath" /><xsl:template match="/"><xsl:copy-of select="//*[@id=$xpath]"/></xsl:template></xsl:stylesheet>';         if(document.all){             this.xsl_object = new activexobject("msxml2.freethreadeddomdocument.3.0");             this.xsl_object.async=false;             this.xsl_object.loadxml(this.xsl_string)             tmp = new activexobject("msxml2.xsltemplate.3.0");             tmp.stylesheet = this.xsl_object;             this.xsl_processor = tmp.createprocessor();         }else{           this.xsl_object = (new domparser()).parsefromstring(this.xsl_string, "text/xml");             this.xsl_processor = (new xsltprocessor());             this.xsl_processor.importstylesheet(this.xsl_object);             this.ownerdocument = document.implementation.createdocument("", "test", null);         }         this.xml = pthis;         this.cloneandplace = _cloneandplace;         return          function _cloneandplace(pthis,pthat,ptext){            var lthat = $x(pthat);              if(document.all){                 this.xsl_processor.addparameter("xpath", pthis);                 this.xsl_processor.input = this.xml;                 this.xsl_processor.transform;                 var newfragment = this.xsl_processor.output;              }else{                  this.xsl_processor.setparameter(null, "xpath", pthis);                  var newfragment = this.xsl_processor.transformtofragment(this.xml,this.ownerdocument);              }              if(lthat){                 if(document.all){                  lthat.innerhtml='';                  lthat.innerhtml=newfragment;                 }else{                  lthat.innerhtml='';                  lthat.appendchild(newfragment);                 }              /*              in ie newfragment string              in ff newfragment dome node (more useful)              */              return newfragment;              }         } } 

Comments