How to call synchronous ajax call in alfresco?

后端 未结 2 1553
天涯浪人
天涯浪人 2021-01-23 23:42

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

2条回答
  •  广开言路
    2021-01-24 00:28

    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
    }
    

提交回复
热议问题