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

Examples of AJAX calls to Confluence XWork actions?

Jim Bethancourt
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.
September 22, 2011

Hi all,

Are there any plugins with source available that make AJAX / XmlHttpRequest calls? I'd like to try and make AJAX calls from a Velocity template and have an idea, but I'd like to see how other plugins do this as well. If you know of a Velocity template and a corresponding XWork action in the Confluence source, that would work as well.

Feel free to tag / suggest tags for this question if you feel it applies to the development of plugins for other applications.

Thanks,

Jim

1 answer

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
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 22, 2011

You can use jQuery's ajax method to make an asynchronous call to a Confluence XWork action.

If you want to return JSON from the Action, the easiest thing to do is make your Action implement the com.atlassian.confluence.core.Beanable interface. In the getBean() method you can return an object and it will get serialised to JSON automatically.

You can pass any parameters to the Action as query parameters in the ajax call. (eg. /confluence/my-url/myaction.action?parameter=true).

The script to call the action would look something like this:

var requestSettings = {
                async: true,
                url: AJS.params.contextPath + "/actions/my-action-path/myaction.action
                timeout: 30000, // 30 seconds.
                success: function(data) {
                    AJS.log("request successful");
// do something with the data.
}, error: function(data) { AJS.log("request failed."); } }; $.ajax(requestSettings);

Jim Bethancourt
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.
September 29, 2011

Thanks Joseph! I see how it all fits together -- thanks for your help!

Mahebub Sayyed February 9, 2015

com.atlassian.confluence.core.Beanable interface is Deprecated Interfaces. What is the alternative solution?

Like Jimmy Quinn likes this
TAGS
AUG Leaders

Atlassian Community Events