AnsweredAssumed Answered

How can i make a synchronous request with Alfresco.util.ajax ?

Question asked by 4535992 on Oct 7, 2017
Latest reply on Oct 10, 2017 by 4535992

Hi i must call a webscript on the repo tier , and wait for is response so i'm need to make a synchronous request (a no ajax request), i'm finding hard time to make this with the api javascript of alfresco, i just don't want to import some external library like jquery  or alfresco-js-api for resolved this issue , there is some function under lafresco 5 for make this happen with alfresco script api.

here a piece of code of my problem:

 

<script type="text/javascript">//<![CDATA[
YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
{
   var myVar = "";
    Alfresco.util.Ajax.jsonGet({
        url: encodeURI(Alfresco.constants.PROXY_URI + '/myserviceuri'),
        successCallback:
        {
            fn: function loadWebscript_successCallback(response, config)
            {
                var obj = Alfresco.util.parseJSON(response.serverResponse.responseText);
                if (obj)
                {
                    myVar = obj;
                }
            }
        }
    });
    //Now i made a second call but the first call has not set already the myVar variable
    Alfresco.util.Ajax.jsonGet({
        url: encodeURI(Alfresco.constants.PROXY_URI + '/myserviceotheruri?rock='+myVar[key]),
        successCallback:
        {
            fn: function loadWebscript_successCallback(response, config)
            {
                var obj = Alfresco.util.parseJSON(response.serverResponse.responseText);
                if (obj)
                {
                   console.log("SUCCESS:" +obj);
                }else{
                   console.error("myVar is null or empty");
                }
            }
        }
    });
}, this);
//]]></script>


How can i made the first call a not ajax call with the native javascript api of alfresco? without involving some external library?

Outcomes