PL/SQL Process in Oracle APEX fails to respond when triggered via AJAX before the page unloads

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?

Answer №1

Upon further investigation, I discovered that the issue stemmed from the PLSQL process. Thanks to a helpful suggestion in a comment by Tom, I decided to delve into the network tab of my browser's development tools and specifically examined the "Response body" tab under "detailed view". It became clear that while the process was returning the results of the htp.script command, it wasn't actually generating the alert box as intended.

After some troubleshooting, I pinpointed the code within my PLSQL process that was causing the problem:

--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);

To address this issue, I made the following adjustment:

UPDATE apex_collections SET n001 = 0 WHERE c001 = :APP_SESSION and collection_name = 'THE_COLLECTION';

However, in order for this change to take effect, I needed to grant update permission to my database user with the following command:

GRANT UPDATE ON apex_collections TO USER

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Interacting with a 3D model using the mouse cursor in a three

After stumbling upon the three.js library recently, I've been spending several days experimenting with it. I am eager to incorporate a mouse event into my project similar to this example where the head of the skull follows the cursor. However, I want ...

I'm looking for a solution to enable the execution of 'expandRowByClick' only when clicking on a specific area within the row in Ant Design. Any suggestions?

In my quest to create a expandable table row with Ant Design's built-in expandRowByClick function, I encountered a dilemma. The function allows me to expand a row by clicking anywhere in it, but what if I want this feature to apply only to a specific ...

Issue with activating a Modal through a button inside a table row on React

I'm currently working on two files: Modal.js and Users.js. Users.js features a table with an API get query linked to it, and in the last column of the table, there's a dropdown for each row that contains three buttons: View, Edit, and Delete. My ...

Sequelize - issue with foreign key in create include results in null value

When using the create include method, the foreign key is returning null, while the rest of the data is successfully saved from the passed object. This is my transaction model setup: module.exports = (sequelize, DataTypes) => { const Transaction = ...

The script fails to execute on content loaded through AJAX in Django

I have a website with nested div elements that make up a complete set. These elements can be dynamically loaded when the user clicks the "load more" button. The website includes a script that changes the style of the aforementioned div element when the pa ...

Using the useRef hook to target a particular input element for focus among a group of multiple inputs

I'm currently working with React and facing an issue where the child components lose focus on input fields every time they are re-rendered within the parent component. I update some state when the input is changed, but the focus is lost in the process ...

Sending documents to a printer directly from a Rails application

Is there a library or gem in Rails that can be used to print the contents of a web page directly onto paper? I am curious if it's possible to specify only a specific part of the page, such as a div, for printing. Any guidance, advice, or tutorial link ...

Challenge encountered while creating a child tag that can be assigned to multiple parent tags

I have an xml format like the one provided. <xml> <parent id="0"> <child type="name"> </child> <child type="age"> </child> </parent> <parent id="1"> <ch ...

Axios encounters CORS issues, while fetch operates smoothly

After going through various questions on CORS errors to no avail, I am facing a dilemma in my NuxtJS client application. Whenever I try to make a simple POST request using axios, I encounter CORS issues. However, when I switch to using the fetch API, every ...

Different from Local system, the code refuses to work when deployed on the server

I have implemented a basic form where onSubmit it collects the values and passes them to a JavaScript page (via an AJAX call), then sends the data to add.php and returns the result back to the HTML page. The code functions correctly on my local system, but ...

What is the best way to showcase my React App.js in an HTML document?

Is there a way to display my React app file (App.Js) within my Index.html file? <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="icon" href="%PUBLIC_URL%/fav ...

I am looking to present a nested array within an array in a tabular format

This is the structure of my database: [{ "firstName": "Shaun", "salary": [ { "id":1, "rate": 250, }, { "id":2, "rate": 290, } ] },{ "firstName": "Julian", "salary": [ { "id":1, "rate": 750, ...

Modify the color of the title in a bootstrap vue tab

Utilizing bootstrap-vue.js, I created a tab that looks like this: The default color of the tab title doesn't fit with my project theme, so I attempted to change it. I found information on how to modify the tab title in the official documentation at . ...

Discovering repeated values and verifying the value range within table columns can be achieved through the use

Within my table, I have two columns labeled Min Range and Max Range. My objective is to identify duplicate values within these columns while ensuring that no row definition overlaps another. The image below illustrates this concept: https://i.sstatic.net/ ...

Ways to evaluate the amount of traffic on a webpage?

Recently, I encountered an issue while creating a page to showcase blog posts. Each post had the typical social media share buttons like "Facebook like," "tweet this post," and "+1." Additionally, there were some extra JavaScript functions added for variou ...

Web page containing information from IPv6 and IPv4 sources exclusively

Is it possible to have an HTML5 page accessible through both IPv4 and IPv6, while only allowing CSS style and JavaScript from other domains via IPv4? Unfortunately, it seems that this setup does not function properly for pure IPv6 connections. Will th ...

Effortless glide while dragging sliders with JavaScript

In the code below, an Object is looped through to display the object key in HTML as a sliding bar. jQuery(function($) { $('#threshold').change(updateThreshold); function updateThreshold () { var thresholdIndex = parseInt($(&apos ...

Is the exchange between Ajax/jQuery and PHP a two-way street?

My jQuery ajax call looks like this: $.ajax({ type: "POST", url: ajaxurl, data: data, success: function(response){ alert(response); } }); I am retrieving data from PHP using the following code: $data_array = get_data(); forea ...

Implementing a dynamic listbox feature in JSP

I have a setup with two listboxes on my JSP page. The first listbox is initially populated with data from the database. When a user selects an item in the first listbox, I want the second listbox to be filled with corresponding database data using Ajax. Si ...

What is the best way to extract values from a JavaScript function?

As someone who is new to Javascript, I am interested in learning how to retrieve values from a function. In the given code snippet, my goal is to extract TheName, TheHeight, TheGender, and TheSexuality when executing the function so that I can utilize the ...