此处的AJAX,其原理与其他语言中使用的一样,We can define it for each region in the Region Source area, or in the HTML Header area of a page’s attributes.如下所示[参考资料:1]:
var ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=getEmployees',0); ajaxRequest.add('P1_EMPLOYEE_NARROW',narrowText.value); ajaxResult = ajaxRequest.get();// JavaScript Document
DECLARE
Id number(10);
BEGIN
Id:=TRUNC(DBMS_RANDOM.VALUE(0,10000));
INSERT INTO RESULTS (JOB_ID,TEST) VALUES (Id,:P1_VALLUE2SAVE);
COMMIT;
END;
http://apex.oracle.com/pls/otn/f?p=31517:80:2359116662402201::NO
上述例子,在APEX 4.1中运行时为空白页,而APEX没有提示任何错误信息,这时候,我们可以使用下面的url测试Application Process是否正常调用了,结果出现Process Not Found的错误,后来将Application Process名称修改为大写的GET_DETIAL_PROCESS运行成功。
测试url:
http://hostname:8888/apex/f?p=131:16:269493785121911:APPLICATION_PROCESS=GET_DETIAL_PROCESS:::P16_NAME:CLARK
You first have to figure out where the problem of your On-Demand Process is.
The best way to test it is to start the On-Demand Process directly through the proper URL. It’s much easier than calling it from some JavaScript code where you don’t see what is returned.
Use the following syntax to call it:
f?p=application_id:0:session:APPLICATION_PROCESS=process_name:::item-names:item-values
Where:
An example URL would be
http://apex.oracle.com/pls/otn/f?p=33231:0:1725326667635628:
APPLICATION_PROCESS=ApexLib_getLovResult:::APEXLIB_REFERENCE_TYPE,APEXLIB_REFERENCE_ID:ABC,123
The best way to get the correct process name is to copy-paste it from the process definition. It wouldn’t be the first time that there is a type.
Didn’t work? The next step is to replace the existing PL/SQL code of the On-Demand Process with just the following code, to make sure that the call works at least.
HTP.p('Hallo world');
Didn’t work, too? Then I have no clue neither what to do next in such a case. Check again the URL and process name if they are ok.
If you got the “Hallo world” then it seems that your PL/SQL code is raising an exception or thePL/SQL code is syntactically wrong.
To handle the first possibility add an exception handler around your code, to show us the exception which is raised by Oracle.
BEGIN [...Here comes your existing code...] EXCEPTION WHEN OTHERS THEN HTP.p('Error: '||SQLERRM); END;
Does it show an error message? With this error message you should have a hint what’s going wrong in your code. If not, add some HTP.P calls for debugging purpose to your code.
If it still doesn’t show an error message, than it seems that your PL/SQL code is syntactically wrong. Have you already tried to run/compile the code stand alone in SQL*Plus/Toad/SQL Developer?
Happy testing!
【参考文献】
[1]http://www.dba-oracle.com/t_html_db_apex_ajax_application_express.htm
[2]http://apex.oracle.com/pls/otn/f?p=31517:80:2359116662402201::NO
[3]http://www.inside-oracle-apex.com/how-to-test-an-on-demand-process-used-for-ajax/
[4]http://www.packtpub.com/article/ajax-implementation-apex