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

AJAX call to external API in user-macro

krzychus April 28, 2015

Hi, 

I don't know why but all the time I'm getting error: "Error rendering macro 'currentdate' : Error occurred rendering template content"

This is my code:

## @param Name:title=Name|type=string|required=true|desc=Your name
<script type="javascript>
AJS.$.ajax({
  url: URL_WITH_NO_QUOTES,
type: "GET",
contentType: "application/json",
  success: function(msg){
    alert(msg);
  }
});
</script>

what I'm doing wrong here? sad

2 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
Shun Hirayanagi
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.
April 29, 2015

Hi,

I suppose $ is treated as a special character used by Velocity template. So, you need to escape it.
I hope the following code will work.

## @param Name:title=Name|type=string|required=true|desc=Your name

#set($D='$')

<script type="text/javascript">
AJS.${D}.ajax({
  url: URL_WITH_NO_QUOTES,
type: "GET",
contentType: "application/json",
  success: function(msg){
    alert(msg);
  }
});
</script>

Besides, <script type="javascript> in your code should be quoted properly.

0 votes
krzychus April 29, 2015

Yes it is working. Actually I don;t even have to write the $. All I need is:

AJS.ajax ...
TAGS
AUG Leaders

Atlassian Community Events