0

I am using struts2 and tiles framework. in the default load I am loading baselayout.jsp. after tat I am not changing the url. it will remain constant, and the inner part will change using ajax query. Now I need to implement struts form. Struts form action after success and failure trying to reload the complete page. I need to reload the form portion only not the entire page.

Alternative Question: Is it possible to trigger a function in javascript after a struts action is returned

Thanks in Advance Krishna

Krishna
  • 101
  • 4

1 Answers1

0

I hope the following answer is help you.

 $('#formEmp').submit(function(event) {
              //Validate using jquery validator
                if (!$('#formEmp').valid()) {
                    return false;
                }

                // abort any pending request
                if (request) {
                    request.abort();
                }
                // setup some local variables
                var $form = $(this);
                // let's select and cache all the fields
                var $inputs = $form.find("input, select, button, textarea");
                $inputs.prop("disabled", false);
                // serialize the data in the form
                var serializedData = $form.serialize();
                // let's disable the inputs for the duration of the ajax request
                // Note: we disable elements AFTER the form data has been serialized.
                // Disabled form elements will not be serialized.
                $inputs.prop("disabled", true);

                // fire off the request to /form.php
                request = $.ajax({
                    url: "saveEmp",
                    type: "post",
                    data: serializedData
                });

                // callback handler that will be called on success
                request.done(function(response, textStatus, jqXHR) {
                    // log a message to the console
                    alert("Saved Successfully");
                    initForm();
                });

                // callback handler that will be called on failure
                request.fail(function(jqXHR, textStatus, errorThrown) {
                    // log the error to the console
                    alert(textStatus);
                });

                // callback handler that will be called regardless
                // if the request failed or succeeded
                request.always(function() {
                    // reenable the inputs
                    $inputs.prop("disabled", false);
                });

                // prevent default posting of form
                event.preventDefault();

            });
  • OP doesn't need to init a form rather that populate using tiles result and it should be a Java, not PHP. – Roman C Sep 10 '14 at 12:26