1

I have one page form done with Spring MVC. User has to register first and I would like the form to be saved automatically so user can come later to finalize it. Traditional form submission with a timer is not what I'm looking for. Instead, I am planning to use some ajaxy way to send fields to the server at each onFocus event.

Any suggestions for implementations or comments for this approach?

4

4 回答 4

3

I just recently did the same thing. I used JQuery and used their "serialize" function along with their "ajax" function to do the form submission. In my case, rather than use an event-driven approach, I simply saved the serialized form to a variable and checked once a minute to see if a newly serialized form was different from the previously saved one.

于 2009-02-21T18:29:01.863 回答
1

you also can check XT Ajax framework

于 2009-02-24T09:08:26.867 回答
0

I solved this using http://docs.jquery.com/Ajax/serialize as JacobM suggested. The serialized form is then sent as ajax post triggered by a timer.

In Spring MVC I created a very basic controller extending AbstractController and extracted my fields from request.

于 2009-02-25T12:09:40.200 回答
0

Below Js script will help you to make ajax call when ever form field changes.

<script>
  $(document).ready($('.form-control').change(function() {
   $.ajax({
    type : "post",
    url : "http://localhost:8521/SpringExamples/autosave/save.htm",
    cache : false,
    data : $('#employeeForm').serialize(),
    success : function(response) {
     var obj = JSON.parse(response);
     $("#alert").text(JSON.stringify(obj));
     $("#alert").addClass("alert-success");
    },
    error : function() {
     alert('Error while request..');
    }
   });
  }));
 </script>
于 2014-08-08T14:37:28.587 回答