Hi all,
I have 2 questions around AP.require() I currently use to make some request to cloud JIRA from an add-on:
it’s marked as “deprecated” in browser console, what to use instead?
how to trigger a function when the (asynchronous) call is performed, but not from inside the success/error blocks?
Thanks a lot, Fred
daniel
June 12, 2017, 2:22pm
2
Atlassian has provided a migration guide here: https://developer.atlassian.com/static/connect/docs/latest/tutorials/migrating-from-acjs-v3-to-v5.html
Basically
AP.require(['request', 'dialog'], function (request, dialog) {
request({
...
});
});
became:
AP.request({
...
});
Thanks Daniel for pointing the migration page.
One last question: which code pattern to use to trigger a function when the call is finished? Should I invoke the function to trigger from the success {} block, or should I use something else like JS promise? I am wondering what’s the best code pattern for this simple thing…
Thanks again,
Fred
Keep it simple, I reckon. Something like this:
AP.request({
url: url,
type: 'GET',
success: function(text) {
doSuccesStuff();
},
error: function(xhr, statusText) {
doFailureStuff();
}
});