Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with ajax request

GrBr
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 19, 2020

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

1 answer

0 votes
David at David Simpson Apps
Atlassian Partner
October 20, 2020

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
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events