4

I am trying to implement a type="button" on a form that, instead of processing the information through the doPost method, processes the form using the doGet method (mostly for the purpose of being able to update the URL correctly). This specification is making it impossible to use type="submit" or document.form1.submit(), because I must not direct to the doPost method.

I have tried to work around the issue by first submitting the form, and then redirecting the URL on the button click (and vise versa), but I'm having difficulty getting around HttpServletRequest issues, as I need to use the HttpServletRequest from the form submission in the doGet method.

Is there any way to use ajax to make the current form data into an HttpServletRequest on the button click? I'm new to ajax and am unsure of the proper syntax, etc.

Here is the short version of what I've been able to gather in HTML so far:

<form id="form1" method="post" action="">
  <div>
    <input id="edit" type="button" name="edit" value="Edit" disabled="true" onClick="window.location.href='/new'"></input>
  </div>
</form>
<script type="text/javascript">
  $(document).ready(function() {
    $("#edit").click(function() {
      $.ajax({
        type:
        url: '/new',
        data: 
        success:
        error:
        dataType:
      });
    });
  });
</script>
  • just change the method on the form from `POST` to `GET` – Orangepill May 22 '13 at 21:01
  • Alright, I did that (using document.form1.submit() on the onClick call, since I still don't know proper ajax form) but I am left with the same issue - I can submit the data and then update the URL (which does two doGet method calls and I end up with the correct URL and incorrect HttpServletRequest information), or I update the URL and then submit the data and end up with the correct functionality, but the incorrect URL. Ultimately, I need to be able to submit the form and update to the specific URL simultaneously. Thoughts? – Kaitlyn Dornbier May 22 '13 at 21:30
  • sorry misread the original post ... this should be what you're after http://stackoverflow.com/questions/15397006/ajax-forced-url-update-imediately-after-a-form-submission-jquery-php-mysql-htm – Orangepill May 22 '13 at 22:01

1 Answers1

0

Use the following correct code for GET form submission:

<form id="form1" method="get" action="">
  <div>
    <input id="edit" type="button" name="edit" value="Edit" disabled="true" onClick="window.location.href='/new'"></input>
  </div>
</form>
<script type="text/javascript">
  $(document).ready(function() {
    $("#edit").click(function() {
      $.ajax({
        type:
        url: '/new',
        data: 
        success:
        error:
        dataType:
      });
    });
  });
</script>