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?
Solved! Go to Solution.
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>
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>
very simple answer for a very stupid question, ty very much
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.