How do I use JQuery in a plugin to call a rest web API?

Hi I have a plugin which contains a java servlet which calls a web API and returns a JSON object, this all works great when I use this code in the chrome console:

AJS.$.getJSON("http://myLocalServer/jira/plugins/servlet/helloworld")
.done(
function(data)
{
console.log('data', data);
}
)
.fail(
function(error)
{
console.log('error', error);
}
);

however when I place this code in my velocity template

<script>
AJS.$(document).ready(
function()
{
AJS.$.getJSON("http://myLocalServer/jira/plugins/servlet/helloworld")
.done(
function(data)
{
console.log('data', data);
}
)
.fail(
function(error)
{
console.log('error', error);
}
);
);
});

</script>

 

The page freezes, I've debuged jira and put a break point in my servlet and it doesnt seem to be getting called, has anyone else had this trouble? 

Thanks!

 

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in United States

Administrators Cleanup

Good morning, After a long weekend cleaning up, I am still in the cleanup mode 😊. I am curious to know: When do you feel the urgency to cleanup your Atlassian Tools? How many times do y...

24 views 0 0
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you