如何在 alfresco 中调用同步 ajax 调用?

编程入门 行业动态 更新时间:2024-10-12 18:18:58
本文介绍了如何在 alfresco 中调用同步 ajax 调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个自定义属性,比如 XYZ.我想在 blur 事件上验证它.我正在使用 JavaScript(客户端)中的 Ajax 调用一个 web 脚本,但它不等待服务器响应并执行进一步的代码.

I have one custom property say XYZ. I want to validate it on blur event. I am calling one web-script using Ajax from JavaScript(Client) but its not waiting for server response and execute further code.

我正在使用 alfresco 自定义验证.我已经完成了有关自定义验证的所有编码,并且工作正常.问题只是脚本没有等待响应并继续执行进一步的代码.

I am using alfresco custom validation. I have done all coding regarding custom validation and it works fine. The issue is only script is not waiting for response and continue to execute further code.

如何使用 Alfresco.util.Ajax 进行同步 Ajax 调用?

How can I make synchronous Ajax call using Alfresco.util.Ajax?

以下是我已经完成的代码和配置.

Following is my code and configuration which I have done.

  • 我已经完成了一些配置 shar-config-custom.xml 文件,添加了在 js 下调用的强制约束.

  • I have done some configuration shar-config-custom.xml file added mandatory contraint which is calling below js.

    validate1.js

    validate1.js

    Alfresco.forms.validation.validate1 = 函数validate1(字段、参数、事件、表单、无声、消息){var temp = true;

    Alfresco.forms.validation.validate1 = function validate1( field, args, event, form, silent, message) { var temp = true;

    Alfresco.util.Ajax.jsonGet ({ url: Alfresco.constants.PROXY_URI + "myscript/getdata?data=" +field.value, successCallback: { fn: function(response) { temp = response.json.Result; if (temp === "false") { Alfresco.util.PopupManager.displayMessage({ text: "You can not go further" }); temp = false; } }, scope: this } }); return temp; };

  • 变量 temp 总是返回真值.

    variable temp is always return true value.

    推荐答案

    您可以模拟 Alfresco AJAX 同步和异步,如下所示:

    You can simulate an Alfresco AJAX both sync and async as follows:

    function myAlfrescoAjax(wsUrl, async) { // wsUrl: string, the url of your webscript // async: boolean, a false value simulates synchronous var simSync = {}; // define a local variable for simulation Alfresco.util.Ajax.request( { method : "GET", url: Alfresco.constants.PROXY_URI + wsUrl, successCallback: { fn: function (response) { // insert code for succesful response if (!async) clearTimeout(simSync); // resume execution when ready (see below) }, scope: this }, failureMessage: "Server Error", execScripts: true }); // now immediately stop execution (if synchronous) with a timeout that takes longer than you ever expect the time the Ajax call will take // note that this timer is killed on succes of the response function in the Ajax call if (!async) { simSync = setTimeout(function(){ // insert code for the unexpected case the timer elapses fully }, 5000); } return }

    更多推荐

    如何在 alfresco 中调用同步 ajax 调用?

    本文发布于:2023-11-28 14:40:39,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1642821.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:如何在   alfresco   ajax

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!