Hi,
I am developing a standalone gadget for JIRA with HTML and JavaScript. In which I wish to use json to get the username of current via REST API and owner of dashboard to realize the authorization.
According to https://answers.atlassian.com/questions/32731/ajax-calls-in-jira-5-0
I use a similar way to access the database. Nevertheless it does not work - the success function never works.
For the url, I use the whole name - i.e. http://.../currentUser, which could actually work via XMLHTTPRequest - but with XMLXttpRequest I could not fetch the value of a single field....So it is not usable.
Could you please help me to answer this question?
Thanks!
There is the problem: According to the official cite, AJAX is not supported in JIRA any more. So to deal with this issue, I use jQuery instead.
To use the jQuery syntax, simply include this line before any other scripts in the file.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
Then, I implement the functionality in the following way:
$(document).ready(function(){ $("#test").click(function(){ alert("I am here"); $.getJSON("/jira/rest/gadget/1.0/currentUser",function(result){ alert(result.username); }); }); });
The usage is referred from http://www.w3schools.com/jquery/ajax_getjson.asp
Finally it works!!!!!
P.S. Chrome's Javascript Console is so useful! Highly recommended!!!
Hi Menga
I'm new to the whole thing ( JSON, JQUERY, AJAX,etc..,) but I'm technically capable of understanding how things work once I see the code.
Would you kind enough to give me the whole JavaScript file ( a simple sample will do ) where you make the API call to Jira?
1 - How the HTML file looks like?
2 - How the JavaScript looks like?
3 - Did you need to provide the user credentials (<userID>:<password> in base 64 basic authentication)? If you did, then how did you do that? If you don't, then how did your Jira allow you to retrieve the user data?
I'm trying to build an example where my javascript will make API calls to my Jira. Once I get the returned result in JSON format I can parse the result and pump the data to an HTML running on my local HTML.
Thanks a lot for your help
J.N
PS: you could email me your sample code to my email: nguyen7744@yahoo.com.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i think you are trying to get current login user name
if yes then try with following code
jQuery(document).ready(function() { AJS.$.get("/jira/rest/auth/1/session", function (data) { var userName = data.name; }); });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, thank you for your answer!
I have tried but it does not work as well....here is the code:
function getCurrentUserName() { alert("function begins!"); var userName; jQuery(document).ready(function() { AJS.$.get("http://ltsjc-monadu:2990/jira/rest/auth/1/session", function (data) { userName = data.name; }); }); alert(userName); return userName; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is it triggering javascript function?
are you getting any error message?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check thisdoc about REST API
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
which version of jira you are using?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yep, it is in JavaScript. But I did not get any error message... I believe it is JIRA 5.1.7. Oh you just reminded me to test it in HTML rather than Gadget. Let me try it and then post the follow-up.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.