通过调用Ajax的一个Oracle函数上的Oracle APEX v4.2.2当场验证目的目的、函数、当场、Ajax

2023-09-10 13:59:50 作者:踩到姑娘滴小蘑菇

我使用的与Oracle的Apex v4.2.2的Oracle 11g和我想知道如何通过Ajax调用来调用一个Oracle的功能,动态操作中的最佳方式。

I am using Oracle 11g with Oracle Apex v4.2.2 and I was wondering how the best way to call an Oracle function via an ajax call, within a Dynamic Action.

我基本上有一个函数,需要六个参数或者返回的结果无效或有效。

I basically have a function that takes six parameters that either returns the result of 'INVALID' or 'VALID'.

在我的网页,我希望能够接受用户输入的值,一旦他们preSS按钮来处理,我需要通过AJAX检查结果是否为无效或有效并立即present一个对话框,用户通知他们有一个错误。

Within my page, I want to be able to accept the values that the user has entered and once they press the button to process, I need to check via ajax whether the result was 'INVALID' or 'VALID' and immediately present the user with a dialog box notifying them that there was an error.

有没有处理这种类型的Ajax请求调用一个函数,甲骨文APEX v4.2.2中的新手段?

Is there a new means of processing this type of ajax request to call a function, within Oracle APEX v4.2.2?

任何帮助/链接的例子来实现上述,将是巨大的。

Any help/links to examples to achieve the above, would be great.

感谢。

推荐答案

阿贾克斯+顶点4.2 =的 apex.server.process API 它需要有一个过程,在所述页面或应用程序的按需过程点。在这里面,你必须打电话给你的功能,并提供了参数,可以是网页项目。为了提供回报,写值与调用HTTP缓冲区 htp.p

Ajax + apex 4.2 = apex.server.process api It requires you have a process at the on-demand process point of the page or an application process. In it you have to call your function and provide the parameters, which can be the page items. To provide a return, write values to the http buffer with calls to htp.p.

DECLARE
  some_var1 VARCHAR2(50);
BEGIN
  some_var1 := my_package.my_function(:P1_EMPNO, :P1_DEPTNO);
  -- write values back
  htp.p(some_var1);
END;

您可以方便地提供 apex.server.process 与页面项目。进一步的处理是所有的JavaScript。 注意警告:数据类型为默认设置为JSON,因此如果你没有提供其他的默认数据类型和不返回一个JSON字符串,你会得到一个解析错误。所以,如果你在你点播的过程,如无效,则返回一个文本,一定要设置数据类型为text!

You can easily provide apex.server.process with page items. Further handling is all in javascript. Note of warning: the dataType is by default set to JSON, and thus if you provide no other default datatype and do not return a json string you will get a parsing error. So if you return a text within your on-demand process such as INVALID, make sure to set the datatype to text!

apex.server.process ( "MY_PROCESS", {
  pageItems: "#P1_DEPTNO,#P1_EMPNO"
  }, {
    dataType: "text"
  , success: function( pData ) { 
      //pData should contain VALID or INVALID - alert it
      alert(pData);
      if ( pData === 'INVALID' ) {
        // do something here when the result is invalid
        // maybe you want to color something red for example
        alert('The data you have entered is invalid');
      };
    }
  } );

我不会分裂这个在超过必要的动力作用,即使它是可能的。我个人不喜欢试图用一个PLSQL块动态真实的行动,只是因为它是比较模糊的,如果你要处理的返回值来采取行动。 只需设置你的按钮,不提交页面,但采取行动的动力作用定义。然后在动力作用创造类型的一个真正的行动执行JavaScript和使用带有回调(S)有Ajax调用。

I wouldn't split this up in more dynamic actions than necessary, even though it might be possible. I personally am not fond of trying to use a PLSQL block dynamic true action, just because it is more obscure to act on if you want to deal with return values. Just set your button to not submit the page, but action defined by dynamic action. Then in the dynamic action create one true action of type execute javascript, and use the ajax call with callback(s) there.