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 Thursday in United States

Local Atlassian Research Workshop opportunity on Sep. 28th

We're looking for participants for another workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sh...

46 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