Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery regular post WITHOUT Ajax

Tags:

jquery

post

I thought this would be quite simple but the documentation doesn't point me to any solution. I am working on an editor. While i am using $.ajax for saving multiple forms at once i would like to perform the same post but with a complete page reload. how can i achieve that?

Trigger Preview BTN -> Collect Forms -> Regular post to preview.php -> Render preview.php

Any ideas?

Thank you very much!

like image 716
Bosh Avatar asked Oct 10 '10 10:10

Bosh


2 Answers

The simplest way is to just use a normal <form> and a redirect from the server-side. Just use one <form> with all your inputs, no need for JavaScript at all.


If you need to move the elements in preparation for submission (since <form> elements can't be validly nested) then on the jQuery side all you need is to copy the elements into your single <form> (they should have unique names unless you want overlap), like this:

<form id="bigForm" method="post"></form>

Then in jQuery when you want to submit:

$("form :input").appendTo("#bigForm");
$("#bigForm").submit();
like image 134
Nick Craver Avatar answered Sep 20 '22 06:09

Nick Craver


But if you still want to control this in Javascript, then you can simply reload page after $.post request is done or use $('form').submit(); so initiate normal submiting.

like image 42
Māris Kiseļovs Avatar answered Sep 19 '22 06:09

Māris Kiseļovs