المكتبة التقنية ←

AJAX Callbacks في Oracle APEX: طلب صغير وعقد واضح

English version

An Ajax Callback is useful when a page needs a specific server result without a full submit—for example, retrieving an order total after the user changes the selected order.

Define the contract

The browser sends an order identifier. The callback validates it, checks access to that order, calculates the result, and returns JSON. The browser then updates the relevant part of the page.

apex.server.process(
  'GET_ORDER_TOTAL',
  { x01: apex.item('P15_ORDER_ID').getValue() },
  { dataType: 'json' }
).done(function (data) {
  apex.item('P15_TOTAL').setValue(data.total);
}).fail(function () {
  apex.message.alert('Unable to load the total. Please try again.');
});

This illustrative client example assumes the named callback and items exist. The callback must produce a matching JSON response. Use APEX_JSON rather than assembling JSON through string concatenation.

Keep authorization on the server

An identifier in x01 is untrusted input. A hidden item or disabled control does not prove that the caller can access the record. Check both the operation and the requested row.

If the user can change the selection rapidly, handle stale responses so an earlier request cannot overwrite a newer selection. Show loading and failure states.

The callback runs when your JavaScript or Dynamic Action invokes it. It is not automatically a stage in every page render. Ajax also does not automatically run all the validations and processes of a normal page submit.

Reference: Oracle Dynamic Actions and framework events.

النسخة العربية

Ajax Callback مفيد لما تحتاج نتيجة محددة من السيرفر بدون Submit كامل، زي جلب إجمالي طلب بعد تغيير الطلب المختار.

حدد شكل الطلب والرد

المتصفح يرسل رقم الطلب، والـCallback يتحقق من القيمة وصلاحية الوصول للسجل، ويحسب النتيجة ويرجع JSON. بعدها المتصفح يحدث الجزء المطلوب. ده مثال لطلب GETORDERTOTAL وتحديث P15_TOTAL، بشرط وجود الـItems والـCallback واستجابة JSON مطابقة.

apex.server.process(
  'GET_ORDER_TOTAL',
  { x01: apex.item('P15_ORDER_ID').getValue() },
  { dataType: 'json' }
).done(function (data) {
  apex.item('P15_TOTAL').setValue(data.total);
}).fail(function () {
  apex.message.alert('تعذر تحميل الإجمالي. حاول مرة أخرى.');
});

استخدم APEX_JSON لتكوين الرد بدل تركيب JSON يدويًا بالنصوص.

الصلاحيات تتطبق على السيرفر

القيمة المرسلة في x01 مدخل غير موثوق. وجودها في Hidden Item أو عنصر مقفول لا يثبت إن المستخدم مسموح له يشوف السجل. راجع صلاحية العملية وصلاحية السجل نفسه.

لو المستخدم يغير الاختيار بسرعة، امنع استجابة قديمة من الكتابة فوق نتيجة الاختيار الجديد، واعرض حالة التحميل ورسالة واضحة عند الفشل.

الـCallback يشتغل لما JavaScript أو Dynamic Action تستدعيه، مش مرحلة تلقائية في كل تحميل للصفحة. وهو لا ينفذ كل Validations وProcesses الخاصة بالـSubmit تلقائيًا.

الفائدة الأساسية هي طلب صغير له مدخلات ونتيجة ومسؤولية واضحة، مش مجرد استخدام Ajax في كل مكان.

المرجع: أحداث Dynamic Actions في Oracle.