Hello,
I am currently learning to code for Confluence and I am hitting a bit of a wall that nobody can help me with, so here I am. I am trying to do a simple Ajax request to get a piece of information from our API, and I know my URL works (Postman validated), but nothing comes out of the request, as if it never went into the "done" part.
function getTestVersionText(templateData) {
var final_value;
var myurl="url_that_works"
AJS.$.ajax({
dataType: 'json',
url: myurl,
async: false
}).done(function () {
final_value = response.issues[0].key;
}).error(function (xhr, status, error) {
displayErrorMessage("error_message_tailored_for_company");
});
return final_value;
}
Anything that jumps to your eyes as to why this wouldn't work ? If I make the function just return a value directly it shows on the page, so the xml and mapping xml/js page are ok.
Thank you
You were missing a reference to response for a start.
Try something like this:
function getTestVersionText () {
var yourUrl = "/some/path/that/works"
AJS.$.ajax({
url: yourUrl,
type: "GET",
dataType: "json",
success: function (response) {
// callback here
console.log('success', response);
},
error: function (xhr, status, error) {
// callback here
console.error('error', { xhr, status, error });
}
});
// do not return here - use the callback functions success/error
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.