10-07-2017 06:02 AM
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?
10-10-2017 02:11 AM
Making synchronous request is not good practice, I suggest you should change the logic of your code.This kind of situation comes in many cases.Taking the synchronous is not good.
May be changing logic as below will do the magic for you.
<script type="text/javascript">//<![CDATA[
YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
{
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)
{
//Make the second call hereAlfresco.util.Ajax.jsonGet({
url: encodeURI(Alfresco.constants.PROXY_URI + '/myserviceotheruri?rock='+obj[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>
10-10-2017 02:11 AM
Making synchronous request is not good practice, I suggest you should change the logic of your code.This kind of situation comes in many cases.Taking the synchronous is not good.
May be changing logic as below will do the magic for you.
<script type="text/javascript">//<![CDATA[
YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
{
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)
{
//Make the second call hereAlfresco.util.Ajax.jsonGet({
url: encodeURI(Alfresco.constants.PROXY_URI + '/myserviceotheruri?rock='+obj[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>
10-10-2017 02:55 AM
very simple answer for a very stupid question, ty very much
Explore our Alfresco products with the links below. Use labels to filter content by product module.