Stop Using jQuery.ajax Directly
Many APEX developers use $.ajax or fetch for server calls. While these work, apex.server.process is purpose-built for APEX and handles session management, CSRF tokens, page item submission, and error handling automatically.
Basic Usage
apex.server.process("GET_CUSTOMER_DETAILS", {
x01: customerId,
x02: "ACTIVE",
pageItems: "#P10_DEPT_ID,#P10_STATUS"
}, {
success: function(data) {
apex.item("P10_CUSTOMER_NAME").setValue(data.name);
apex.item("P10_BALANCE").setValue(data.balance);
},
error: function(jqXHR, textStatus, errorThrown) {
apex.message.alert("Error: " + errorThrown);
},
dataType: "json"
});
The Server-Side Process
DECLARE
l_cust_id NUMBER := TO_NUMBER(APEX_APPLICATION.G_X01);
BEGIN
APEX_JSON.OPEN_OBJECT;
FOR rec IN (SELECT customer_name, balance FROM customers
WHERE customer_id = l_cust_id) LOOP
APEX_JSON.WRITE('name', rec.customer_name);
APEX_JSON.WRITE('balance', rec.balance);
END LOOP;
APEX_JSON.CLOSE_OBJECT;
END;
Sending Arrays With f01
apex.server.process("SAVE_SELECTIONS", {
f01: ["100","200","300"],
x01: "APPROVE"
}, {
success: function(data) {
apex.message.showPageSuccess("Saved " + data.count + " items.");
apex.region("myReport").refresh();
}
});
-- Server side
FOR i IN 1 .. APEX_APPLICATION.G_F01.COUNT LOOP
process_item(APEX_APPLICATION.G_F01(i));
END LOOP;
Promise-Based (Modern Approach)
apex.server.process("VALIDATE_ORDER", {x01: orderId}, {dataType:"json"})
.done(function(result) {
if (result.valid) { submitPage(); }
else { apex.message.showErrors([{type:"error",location:"page",message:result.message}]); }
})
.fail(function() { apex.message.alert("Server communication failed."); });
Key Advantages
Session token included automatically. Page items sent as if submitted. APEX session timeout handled gracefully. No URL construction needed. Responses routed through APEX error handling.