在 Oracle APEX v4.2.2 中通过 Ajax 调用 Oracle 函数以进行现场验证 [英] Calling an Oracle function via Ajax for on-the-spot validation purposes in Oracle APEX v4.2.2

查看:30
本文介绍了在 Oracle APEX v4.2.2 中通过 Ajax 调用 Oracle 函数以进行现场验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Oracle 11g 与 Oracle Apex v4.2.2 结合使用,我想知道如何在动态操作中通过 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'.

在我的页面中,我希望能够接受用户输入的值,一旦他们按下按钮进行处理,我需要通过 ajax 检查结果是无效"还是有效"并立即呈现使用对话框通知用户出现错误.

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.

在 Oracle APEX v4.2.2 中是否有一种新的方法来处理此类调用函数的 ajax 请求?

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

推荐答案

Ajax + apex 4.2 = apex.server.process api
它要求您在页面的按需处理点或应用程序流程处有一个流程.在其中您必须调用您的函数并提供参数,这些参数可以是页面项目.要提供返回值,请通过调用 htp.p 将值写入 http 缓冲区.

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 中.
警告说明:dataType 默认设置为 JSON,因此如果您不提供其他默认数据类型并且不返回 json 字符串,您将收到解析错误.因此,如果您在按需流程中返回文本(例如 INVALID),请确保将数据类型设置为文本!

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 类型的操作,并在那里使用带有回调的 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.

这篇关于在 Oracle APEX v4.2.2 中通过 Ajax 调用 Oracle 函数以进行现场验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆