0

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>
Dan
  • 2,086
  • 11
  • 71
  • 137

2 Answers2

1

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.

Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110
  • 1
    This looks good, to help you construct the right url in a portable way use the struts2 url tag in place of where "location/to/my/file.xml" is found in this answer. Also use the struts2-json plugin and work with json instead of xml. – Quaternion Mar 16 '12 at 05:44
0

You're trying to fire two submits. $ is a function that returns an object. 'submit' is a method of that object. If the jquery object is holding a form, it's like pressing the submit button on that form so the page refreshes and all the remaining code doesn't matter. You're trying to submit twice but $(this).submit doesn't really make sense.

If I had to guess, maybe you want something more like this:

$('#formId').submit( function(e){
    e.preventDefault(); // stops the page from reloading
    //maybe ajax or something else to change this div you're talking about.
} )
Erik Reppen
  • 4,605
  • 1
  • 22
  • 26