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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

AJS.$.ajax call producing ParseErrorException

Edited
I am using following code in velocity template for Project Tab Panel plugin module.
<script>
AJS.$(document).ready(function() 
{
	alert(getCurrentUserName());
   
});


function getCurrentUserName()
{
	var user;
     AJS.$.ajax({
        url: "/rest/gadget/1.0/currentUser",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
        } 
     });
     return user;
}

</script>

When I visit my tab panel I get this error message.....

 

An error occurred whilst rendering this message. Please contact the administrators, and inform them of this bug. Details: ------- org.apache.velocity.exception.ParseErrorException: Encountered "{" at com.elixir.jira.CustomerIssuesProjectTabPanel:cs-customers-only/templates/tabpanels/cs-customers-only.vm[line 17, column 17] Was expecting one of: <EOF> "(" ... <RPAREN> ... <ESCAPE_DIRECTIVE> ... <SET_DIRECTIVE> ... "##" ... "\\\\" ... "\\" ... <TEXT> ... "*#" ... "*#" ... <STRING_LITERAL> ... <IF_DIRECTIVE> ... <STOP_DIRECTIVE> ... <INTEGER_LITERAL> ... <FLOATING_POINT_LITERAL> ... <WORD> ... <BRACKETED_WORD> ... <IDENTIFIER> ... <DOT> ... "{" ... "}" ... at org.apache.velocity.Template.process(Template.java:141) at

 

Please note that all AJS functions are working .. it produces error on ajax calls only .. what is the solution .. I have been stuck in it like forever...

 

 

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Florin Manaila
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.
Sep 17, 2013

The problem is that the velocity engine is interpreting the "$." from "AJS.$.ajax" as a valid directive. You should include all the javascript in a web-resource and then include it in the velocity file (or require it from your panel class) so it won't be parsed.

See this for more info: https://developer.atlassian.com/display/JIRADEV/Web+Resource+Plugin+Module#WebResourcePluginModule-ReferringtoWebResources

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
Sep 17, 2013

So just try it with jQuery.ajax instead of AJS.$.ajax?!

Am I wrong or should work, when velocity is ignoring the block?

#[[<script>...</script>]]#
Florin Manaila
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.
Sep 18, 2013

I've had some trouble using jQuery directly and that's why I usually try to avoid that syntax, but yes, that should work as well.

I've never used #[[ ]]#, but if it does what you say, it should work. Maybe the velocity engine in JIRA is outdated (?).

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
Sep 18, 2013

I dont think any engines in JIRA are outdated...

Florin Manaila
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.
Sep 18, 2013

Looking into the sources for JIRA 6.0.5, they use a custom version of the velocity engine 1.6.4-atlassian-4, which I guess is based on velocity 1.6.4. The #[[ ]]# syntax was added in version 1.7 according to their changelogs ( http://velocity.apache.org/engine/releases/velocity-1.7/changes-report.html ) and this https://issues.apache.org/jira/browse/VELOCITY-661 , so that's probably why it doesn't work.

0 votes
RambanamP
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.
Sep 17, 2013 • edited Jul 25, 2019

try with this script

<script type="text/javascript">
jQuery(document).ready(	function($) {
//you can get current user like this
alert("User :: "+AJS.params.loggedInUser );	
alert(" RemoteUser :: "+AJS.params.remoteUser);	

//or like this
 alert(getCurrentUserName());
function getCurrentUserName()
{
    var user;
     AJS.$.ajax({
        url: "/rest/gadget/1.0/currentUser",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
        } 
     });
     return user;
}

});
</script>

 

 

0 votes
Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
Sep 17, 2013

The Script works as expected, when I excecute it in firebug.

You can try to avoid velocity parse the scriptblock by writing:

#[[<script>...</script>]]#

As described here: http://stackoverflow.com/questions/6828342/velocity-how-to-avoid-parseerrorexception-when-using-jquery

Nope .. not working ..

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
Sep 17, 2013

But you can excecute it in firebug?

TAGS
AUG Leaders

Atlassian Community Events