0
votes

I'm working on alfresco maven sdk project.

So i have a repo webscript who return a json response template containinng the list of files contained in a specific folder (in my case it's: Espace%20racine/Dictionnaire%20de%20données/Dossier%20Workflow).

The template response.json.ftl is here:

{ 
  "Files" : [
    <#list folder.children as child>
    <#if child.isDocument>
    {
        "name" : "${child.name}"
    }
    <#if child_has_next>,</#if>
    </#if>
  </#list>
  ]
}

My webscript works fine, and when i run it through the commande line or the browser, i get a response like:

    { 
"Files" : [
        {
        "name" : "test"
    }
    ,
    {
        "name" : "test2"
    }
    ,
    {
        "name" : "test3"
    }

  ]
}

Now, i want to invoke my webscript from a javascript file who reside in the folder web of share, but i haven't idea to how achieve this. I searched on the net but i don't find a consistant example to how manage this.

It'll help me lot if anyone can tell me the way to achieve this or take me an example to how achieve this.

1

1 Answers

0
votes

Below is the code for making an ajax call in alfresco share.There are other methods also available like Alfresco.util.Ajax.jsonPost,Alfresco.util.Ajax.jsonPut etc..In below console.log(response.json) will print the response in console.

 var fnSuccess = function RESPONSE_functionName(response)
     {
        console.log(response.json)//Here you will get response json.
     };
     var fnFailure = function RESPONSE_functionName(response)
     {
        Alfresco.util.PopupManager.displayMessage({text:"Failure"});
     };
    Alfresco.util.Ajax.jsonGet(
     {
        url: Alfresco.constants.PROXY_URI + "REPOSITORY_WEBSCRIPT_URL",
        successCallback:
        {
           fn: fnSuccess,
           scope: this
        },
        failureCallback:
        {
           fn: fnFailure,
           scope: this
        }
     });