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 Friday in Jira Service Desk

Looking for anyone who has switched from Zendesk to Jira Service Desk

Hi Community! The Jira Service Desk marketing team is looking for customers who have successfully switched from Zendesk to Jira Service Desk!   We’d love to hear your thoughts on the pros and ...

42 views 2 2
Join discussion

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