如何调用露天同步Ajax调用? [英] How to call synchronous ajax call in alfresco?

查看:108
本文介绍了如何调用露天同步Ajax调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义属性说某某。我想验证它的模糊事件。 我打电话使用Ajax从JavaScript(客户端)一台Web脚本,但它不是在等待服务器响应并执行进一步的code。

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.

我使用的露天自定义验证。我已经做了所有的编码有关自定义的验证,它工作正常。问题是唯一的脚本是不是在等待回应,并继续执行进一步的code。

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.

如何才能使同步Ajax调用,使用 Alfresco.util.Ajax

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

以下是我的code和配置,我做的事。

Following is my code and configuration which I have done.

  1. 我已经做了一些配置莎尔 - 配置 - custom.xml文件中添加的强制性约束实现它调用下面的js。

  1. 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(        现场,ARGS,事件,形式,沉默,消息){      VAR温度= 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.

推荐答案

您需要使用可用的功能的回调,因为这些被称为操作完成后。你有一failureCallback和一个successCallback。

You need to use the callbacks available on the function as these are called after the operation has completed. You have one failureCallback and one successCallback.

下面是一个JavaScript jsonPost功能的使用successCallback一个例子:

Here is an example of a JavaScript jsonPost function using a successCallback:

Alfresco.util.Ajax.jsonPost(
    {
        url: Alfresco.constants.PROXY_URI + "my/webscript?nodeRef=" + nodeRef,
        successCallback: {
            fn: function (o) {

                //Make further calls

            },
            scope: this
        },
        failureMessage: "Server Error"
    });

如果你想,那么你需要覆盖露天的相关部分和移动调用回调函数来阻止进一步的code。

If you want to block further code then you need to overwrite the relevant part of Alfresco and move the calls to the callback.

这篇关于如何调用露天同步Ajax调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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