0

I would like to use Ajax to perform an action in OFBiz without the page refreshing. The task will be like filters. When I choose any Checkbox it should perform some action and display the result in the very same page.

What are all the steps i need to do?

I would appreciate some sample code for controller.xml,javascript calling Ajax ..etc

Thanks.

Louis van Tonder
  • 3,664
  • 3
  • 31
  • 62
Shankar
  • 13
  • 1
  • 6

2 Answers2

0

You can use form submission through ajax on an event in your ftl's. Here's a sample code for ajax call from say an ExampleCreateParty.ftl:

$.ajax({
              url: '<@ofbizUrl>addSecurityPermissionToSecurityGroup</@ofbizUrl>',
              type: 'POST',
              accepts: 'xml',
              data: $("form#Permissions").serialize(),
              success: function(e) { console.log(e);
                var xmlDoc; 

                 try {
                    xmlDoc = $.parseXML(e);
                    var error = $(xmlDoc).find("Message").find("Error").find("ErrorCode").text(); 
                    var errorMsg = $(xmlDoc).find("Message").find("Error").find("ErrorMessage").text(); 
                    if (error=='0'){alert(errorMsg);} 
                    console.log(xmlDoc);
                } catch (err) {
                    alert('Saved Successfully!');
                } 
                },
              error: function(e) { console.log(e); }
              })

Here in response to the service called i.e. addSecurityPermissionToSecurityGroup you can specify the response in the controller.xml which you can get within the success key in the ajax call itself.

DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105
newbie
  • 663
  • 2
  • 6
  • 19
  • I used like this, but it doesn't reach java file ie action defined in controller. can you give some source of javascript onselct checkbox,controller.xml, and a java sources to return response – Shankar Aug 29 '13 at 07:00
0

To see a full end-to-end example have a look at this OFBiz page

As you can see whenever you change the product configuration, the product price is updated with Ajax call. Then you can find out for yourself the freemarker file containing javascript and the controller doing calculations and returning it back.

Bilgin Ibryam
  • 3,345
  • 2
  • 19
  • 20