In my Oracle APEX 4.2 environment, I created a PLSQL process set to execute "On Demand - When this process is called by AJAX." The purpose of this process is to update two member attributes in a collection that I established when the page loaded. Here is the code for the process:
DECLARE
v_seq_id NUMBER;
BEGIN
--get sequence id
SELECT seq_id into v_seq_id FROM apex_collections
WHERE collection_name = 'THE_COLLECTION' and c001 = :APP_SESSION;
--I attempted uncommenting this script to check if it works as well
--htp.script('alert(''PLSQL Process works'');');
--update first member attribute
apex_collection.update_member_attribute(
p_collection_name =>'THE_COLLECTION',
p_seq => v_seq_id,
p_attr_number => 2,
p_attr_value => 0);
--update second member attribute
apex_collection.update_member_attribute(
p_collection_name =>'THE_COLLECTION',
p_seq => v_seq_id,
p_attr_number => 3,
p_attr_value => sysdate);
END;
When attempting to call this process with AJAX/javascript before unloading the page, nothing occurs. I placed this code in the "Execute on Page Load" section of my page:
window.onbeforeunload = function(){
//this alert box functions, confirming the function is called
alert('Unloading...');
//call the PLSQL process
var get = new htmldb_Get(null,$v('pFlowId'), 'APPLICATION_PROCESS=THE_PROCESS',1234);
get.get();
//this also executes, indicating the function completes
alert('end');
};
I have tested this in two ways. Firstly, I included logic in my page dependent on whether these member attributes were updated. Upon reloading the page, it appears as though the PLSQL process did not run. Secondly, I tried uncommenting the htp.script line in the PLSQL code above, but it still does not execute.
Upon running the following code in my browser's F12 tools, the console prints "alert('test');" without displaying an error message:
var get = new htmldb_Get(null,$v('pFlowId'), 'APPLICATION_PROCESS=THE_PROCESS',1234);
get.get();
I also attempted running it with window.onload, but that did not seem to work either.
Running the PLSQL process as an "After Header" process successfully launches an alert box from the htp.script code and the process seems functional.
Is there a way to make this work with AJAX? Could I be overlooking something obvious?