I am trying to understand how AJAX Callbacks work.
I want to perform a DA when a Textfield loses focus IF a certain backend condition is met (i.e. I want to Execute Javascript that will check against an AJAX Callback process).
This is the Javascript code to execute:
apex.server.process(
"MY_PROCESS",
{
pageItems: "#P302_COUNTRY_CODE"
},
{
dataType: "text",
success: function( pData ) {
if (pData === 'YES') {
console.log('YES');
return(true);
} else {
console.log('NO');
return(false);
}
}
}
);
And this is the AJAX Callback (PL/SQL):
DECLARE
pHasProvinces INTEGER;
BEGIN
SELECT COUNT(*)
INTO pHasProvinces
FROM SUBDIVISION
WHERE
SUBDIVISION_LEVEL = 3 AND
COUNTRY_CODE_ALPHA2 = :P302_COUNTRY_CODE;
IF pHasProvinces > 0 THEN
htp.p('YES');
ELSE
htp.p('NO');
END IF;
END;
I have reviewed the documentation here. But unfortunately, I can not find an example on the PL/SQL process to implement.
Any help with the above code is welcomed. Also I am wondering if htp.p is the way to return a value in Apex18.
Apex 18.2.0.00.12
Oracle 18c XE