Well, first of all, thank you for the response. But your code doesn't work in browser console so it won't work in the Freemarker template :/
My goal is to call custom repository Webscript from control in the task-edit in the Alfresco Share.
I didn't want to hard-code alfresco URL ("http://localhost:8080") in the .ftl file so I though it might be a function for it.
Unfortunately, now I see that there is a much bigger problem. Authentication in the Share in not enough for Repo. (i set up my web-script to "<authentication>user</authentication>").
Do you have any idea how can I "pass authentication" from Share to Repo?
Right now I'm getting 401 Unauthorized error.
I also tried using share Proxy ("http://localhost:8180/share/proxy/alfresco ") - no authorization problems this time but it does not always behave in the same way - it does return only a fraction of JSON with an empty JSONArray! It happens only while using share Proxy AND while not passing any URL parameters
EDIT. It was an external server's fault. Alfresco Share adds additional parameter to URL (alf_ticket) and it disrupted server logic.
Sorry for trouble.