Missed Team ’24? Catch up on announcements here.

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

AJAX calls in Jira 5.0

Brad Tibbils January 31, 2012

Hello,

I'm trying to upgrade from Jira 4.2.3 to Jira 5.0. I have several javascript snippets (that I have placed in the descriptions for certain fields) that make a simple AJAX call to a server-side php file that then grabs some information from the database and sends it back. These all work fine in 4.2.3. However in 5.0 I am unable to make even the simplest AJAX call.

The closest I've come so far: I'm testing with an AJAX call that gives me an alert box of the responseText. The alert box is blank but in Firebug I can see the response and the status says "301 Permanently Moved". I'm using the code below to make the AJAX call:

<script type="text/javascript">

if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); 
else if (window.ActiveXObject) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

xmlhttp.open("GET",'/scripts/getgroups.php',true);
xmlhttp.send(null);
xmlhttp.onreadystatechange = function() { 
	if (xmlhttp.readyState==4) alert( xmlhttp.responseText ); 
}

</script>

The only thing I've found in the documentation is this which, if I'm reading it correctly, says that AJAX calls are no longer supported out of the fear that it might not load in time? If this is true is there a way to override this (something like, "edit this file to disable that security feature")? I saw that it was recommended to use .live() or .delegate() but I still have to make an AJAX call. I've also tried the jQuery version (code below) but it's the same problem.

<script type="text/javascript">
	AJS.$.ajax({
	  url: "/scripts/getgroups.php",
	  type: "GET",
	  success: function(msg){
		alert(msg);
	  }
	});
</script>

Hopefully I'm missing something simple here. Thank you for any help you can provide,

Brad

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
JamieA
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.
January 31, 2012

There's nothing in jira that could stop you running ajax requests as far as I know.

I would say the problem is going to be something simple... is the/scripts/getgroups.php really there, in relation to the url you are accessing jira from?

You probably are actually getting the 301.

> The only thing I've found in the documentation is this which, if I'm reading it correctly, says that AJAX calls are no longer supported out of the fear that it might not load in time?

That's not my reading of it... AFAIK it says you can't load javascript from custom field classes using the resourcemanager, because the page has already loaded.

Brad Tibbils January 31, 2012

Hi Jamie,

Thanks for the quick reply. I know it's in the right place because I can see the response I'm expecting in Firebug. It just doesn't let my javascript access it or view it (or something). I've also tried the full URL path with the same outcome.

I'm glad this isn't unsupported (I assume you were able to do it successfully in Jira 5.0).

Thanks again. I guess I'll just have to stare at it a little longer. :)

Brad

JamieA
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.
February 1, 2012

Hi... it's all on the same host, same port right? Ie this is not browser anti-XSS stuff causing the problems? I recommend you install Fiddler... this will let you see all the requests and responsers, with headers, content, etc.

Brad Tibbils February 1, 2012

Ok, finally got it. It was a combination of using https (instead of http) and setting up my apache config file correctly (I had it pointing to scripts folder for http but not https).

Thank you for your help.

TAGS
AUG Leaders

Atlassian Community Events