Search code examples
javascriptjquerystruts2struts-config

unable to give exact target to refresh my div in jquery function


sir, when i click on "Rename Day button" jquery popop calender appears in my screen , once if i click on its submit button it is forwarding to my page but is not refreshing the exact div.. I do not where should i specify div target for refreshing my particular div..

jquery function for submit

  function okButton(){

            $("#formId").submit();
           };
$(this).submit({
            target: '#userTemplateRightmiddlediv'});
        };

struts.xml

 <!-- Rename Selected Day for User Template -->
    <action name="EditDayAction"class="com.ebhasin.fitnessbliss.dao.DynamicTableOperationsService" method="RenameDayUserTemp">
        <result name="success">/jsps/userTemplateRightmiddlediv.jsp</result>
    </action>

Solution

  • Extend the functionality of your 'okButton' to stop the default form submission behavior, then create an ajax function to connect to your XML file, return the data, and then insert the data into the .html() of the element with an ID of userTemplateRightmiddlediv

    function okButton(){
      $("#formId").submit(function(e){ //'e' for 'event'
        e.preventDefault();//stop the page from refreshing
        $.ajax({
          url: 'Struts2 URL Here',
          dataType: 'xml',
          success: function(xml){
            //function(xml) represents an object returned from our XML file, we can work with it however we want by using normalized jquery procedures
            $("#userTemplateRightmiddlediv").html(xml);
          }
        });
      });
    }
    

    Edit

    Changed to reflect portability with Struts 2.