Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Ajax request always failing

Declan Murphy July 7, 2015

I am trying to create a script that hides a field if an issue is in a particular status. To get the status, I am making an ajax request to the Rest API. However, this request keeps failing and I'm not sure why.
The ajax request is as follows:

function getStatus() {
        var issueKey = JIRA.Issue.getIssueKey();
        var restUrl = "/rest/api/2/issue/" + issueKey;
        var statusname;
        console.log('KEY : ' + issueKey);
        console.log('URL : ' + restUrl);
        
        AJS.$.ajax({
            url: restUrl,
            type: 'get',
            dataType: 'json',
            contentType: "application/json",
        })
		.done(function(data) {
            statusname = data.fields.status.name;
            console.log('Status Name : ' + statusname);
            return statusname;
        })
        .fail(function() {
            console.log('ERROR');
        })
        .always(function(data) {
            console.log('DATA : ' + data);
        });
 }

Could someone tell me why this is failing and where I've gone wrong? Alternatively, is there an easier/short-hand way to get the status of an issue?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2015

What HTTP status does it return? Is there respsonse body?

TAGS
AUG Leaders

Atlassian Community Events