Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@stefandobre
Last active February 10, 2021 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefandobre/726d37e04d85ff0daac76534b696cf0e to your computer and use it in GitHub Desktop.
Save stefandobre/726d37e04d85ff0daac76534b696cf0e to your computer and use it in GitHub Desktop.
/*
In case the browser asynchronously called the server via AJAX,
this is how we can handle that request in JavaScript (MLE)
*/
let response = {};
try {
// execute any business logic here
apex.conn.execute(…);
// dummy response
response = {
status: 'success',
anArray: [1, 2, 3],
nestedObject: {
simple: 'nesting'
}
};
// JSON operations are trivial
response.nestedObject.simple = 'alteration';
} catch(e) {
// in case of any errors, rollback any changes
// and inform the browser of the error if in debug mode
apex.conn.rollback();
response.status = 'error';
if(apex.env.debug != 'NO'){
response.message = e.ORACLE_ERROR_MSG;
}
}
// sending the response back to the browser
apex.conn.execute('begin sys.htp.p(:1); end;', [JSON.stringify(response)]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment