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

Mick Murphy May 31, 2017

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