Missed Team ’24? Catch up on announcements here.

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

$.post(url) for a form in a velocity does not work

rpenkert June 19, 2015

Hi,

i want to redirect to another URL as the post in velocity is going to.

My velocity:

<form id="pickTemplate" class="aui" method="POST" action="TemplatePost.jspa">
     <div class="field-group">
       <label for="template-name">Templates:</label>
           <select id="template-name" name="template" class="select">
             #foreach($template in $action.allTemplates)
                <option value=$template.getID()> $template.getName() </option>
              #end 
            </select>
     </div>
       <div class="buttons-container">
          <div class="buttons">
            <input id="saveTemplate" type="submit" class="button submit" value="Speichern">
          </div>
       </div>
</form>

My javascript:

AJS.$("#pickTemplate").submit(function(){
       AJS.$.post("baseurl/secure/TemplatePost.jspa", function() {
          window.location = "baseurl/browse/".concat(something);
        });
        return false;
      });

But the Post-block is not called. I got redirected to 'baseurl/browse/something' but the post-block wasn´t called.

 

When I don´t use the javascript and the post in the velocity is called, it works. But then i´m on the page 'TemplatePost'

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
rpenkert June 22, 2015

The solution is to read the API more mindful. There is missing something.

AJS.${d}.post("", function(){ ...

There is missing the Data-Parameter with the Data that the Post will send.

AJS.${d}.post("",AJS.$("#pickTemplate").serialize(), function(){ ...

Now, it works.


 

1 vote
Davin Studer
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.
June 19, 2015

I have found when writing velocity in user macros that the velocity renderer gets confused by the "AJS.$.post". To get around this I usually use the below pattern. Not sure if this is the issue you are having, but it might be.

###########################################################################
## These are used for getting around velocity issues when writing jQuery ##
###########################################################################
#set( $d = '$' )
#set( $p = '#' )

<script type="text/javascript">
AJS.$("${p}pickTemplate").submit(function(){
    AJS.${d}.post("", function(){
		window.location = "baseurl/browse/".concat(something);
	});
	return false;
});
</script>
rpenkert June 22, 2015

Thanks for your reply but I use a js-file in my Project. In a other Plugin I uses AJS.$.ajax and it works well. I´m verry confused that the window.location part is called but the Post doesn´t work.

TAGS
AUG Leaders

Atlassian Community Events