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'
Community moderators have prevented the ability to post new answers.
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.
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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.