Pali
Pali

Reputation: 1347

Alfresco: how to call share webscript from client js and extract JSON data

From client-side javascript I want to call a share-webscript which returns JSON data.

The response from getTicket.json.ftl looks like:

{
   "ticket" : "TICKET_faf851d4a993b62c98908268af07876f09fa86c9"
}

So how can I call this share-webscript from my client-side javascript and extract the value of "ticket" ?

see answer below

Upvotes: 0

Views: 1410

Answers (1)

Pali
Pali

Reputation: 1347

Answer:

Alfresco.util.Ajax.jsonGet(
                    {
                        url: Alfresco.constants.PROXY_URI + "/auth/getTicket.json",
                        successCallback:
                        {
                            fn: function(response)
                            {
                                try {
                                    var json = JSON.parse(response.serverResponse.responseText);
                                    var ticket = json["ticket"];
                                    if (ticket.substring(0, 6) == "TICKET") {
                                        clipboardData.setData("Text", ticket + "&" + file.nodeRef);
                                        location.href = Alfresco.constants.URL_RESCONTEXT + "components/javawebstart/AEF_JNLP.jnlp";
                                    } else {
                                        // handle unknown format
                                    }
                                } catch (e) {
                                    // handle error
                                }

                            },
                            scope: this
                        },

                        failureCallback:
                        {
                            fn: function(response)
                            {
                                // handle failure case
                            },
                            scope: this
                        }
                    });

This calles the share tier webscript. So you also need a share tier webscript which calls a repository web script which returns the actual ticket ...

Upvotes: 1

Related Questions