jquery - ajax call to do action when onclick checkbox in ofbiz -
i want use checkboxes options id1,id2.when choose id1 ajax run through javascript , call appropriate action , return response.i dont want reload page.please post freemarker, controller.xml, java codes this.
based on understanding of question, following script might helpful you:
in ftl file itself/ in seperate js file add following script:
<script type="text/javascript"> jquery(document).ready(function(){ jquery("#id1").click(function(){ if(jquery(this).is(":checked")) { var requrl= "checkbox1_url"; sendajaxrequest(requrl); } }); jquery("#id2").click(function(){ if(jquery(this).is(":checked")) { var requrl= "checkbox2_url"; sendajaxrequest(requrl); } }); }); function sendajaxrequest(requrl){ jquery.ajax({ url : requrl, type : 'post', data : {'var1': 'val1', 'var2' : 'val2'}, //here can pass parameters //the request if any. success : function(data){ //you handle response here displaying in required div etc. }, error : function(errordata){ alert("some error occurred while processing request"); } }); } </script>
in freemarker,
<input type="checkbox" id="id1" name="checkbox1" /> <input type="checkbox" id="id2" name="checkbox2" />
in controller.xml:
<request uri="checkbox1_url"> <!-- fire if events here --> <response name="success" type="view" value="viewname1" /> <response name="error" type="view" value="errorviewname" /> </request> <request uri="checkbox2_url"> <!-- fire if events here --> <response name="success" type="view" value="viewname2" /> <response name="error" type="view" value="errorviewname" /> </request> <view-map name="viewname1" type="screen" page="component://.../widget/screensfilename#screenname"/> <view-map name="viewname2" type="screen" page="component://.../widget/screensfilename#screenname"/>
you define 2 screens in widgets specified in above path(page="...." attribute of view-map tag).
Comments
Post a Comment