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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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>]]#

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 (?).

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

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.

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 ..

But you can excecute it in firebug?

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>

 

 

TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you