| Basics of AJAX |
|
|
|
| Monday, 23 November 2009 23:25 |
|
In Application Express(APEX) it is possible to communicate with the database without submitting the entire page. This is extremely useful when your APEX application is being run on a very slow network. This on demand communication is possible in APEX using Asynchronous JavaScript and XML(Ajax). Using this method sends only the minimum information required to retrieve a value from the database. I will explain using a simple example involving the famous emp table.
declare
v_ename emp.ename%type; begin select ename into v_ename from emp where emp_id = :P1_EMPID; htp.prn(v_ename); exception when others then htp.prn('An error occurred retrieving the name'); end; 2. Create the following javascript function. function get_ename(){ /* retrieve the emp_id from the page */ var emp_id = document.getElementById('P1_EMPID').value; /* define the Ajax call. The only variable of note in this example is the application_process, which I have set to be the same name as step 1. */ var get = new htmldb_Get(null,html_GetElement('pFlowId').value, 'APPLICATION_PROCESS=GET_ENAME’,0); /* add the value in P1_EMPID into the session value for P1_EMPID. this is important as without this step the APEX server would not know what value the user had entered */ get.add('P1_EMPID',emp_id); /* call the ondemand process and accept the returning ename */ var gReturn = get.get(); /* set the field on the page to equal the ename retrieved from the database */ document.getElementById('P1_ENAME').value = gReturn; }
|