Hi,

'Tis indeed very easy.  Say you have a form wrapped in a div:

    <div id='formwrapper'><form>
    ....
    </form></div>

You can post it like so and take the result (which is presumed to be
an HTML snippet in this case) and use that to update the container:

    new Ajax.Updater('formwrapper', someurl, {
        parameters:  $('formwrapper').down('form').serialize(true),
        onFailure: function(response) {
            // ...show a failure message...
        }
    });

That uses:

$[1] to find the formwrapper div.
Element#down[2] to find the form within the wrapper.
Form#serialize[3] to grab the form fields and make an object out of
them.
Ajax.Updater[4] to make the request (by default it uses POST) and
update the wrapper on success.

[1] http://prototypejs.org/api/utility/dollar
[2] http://prototypejs.org/api/element/down
[3] http://prototypejs.org/api/form/serialize
[4] http://prototypejs.org/api/ajax/updater

You can also do it without wrapping the form in a div, but it's a
*tiny* bit more work; assuming the form has the ID 'myform' (creative,
aren't I?):

    var form = $('myform');
    new Ajax.Request(someurl, {
        parameters:  form.serialize(true),
        onSuccess: function(response) {
            form.insert({below: response.responseText});
            form.remove();
        },
        onFailure: function(response) {
            // ...show a failure message...
        }
    });

Citations for Ajax.Request, Element#insert, and Element#remove are
left as an exercise for the reader... ;-)

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Aug 18, 3:09 pm, bill <will...@techservsys.com> wrote:
> I've read the docs, but can't seem to figure out how to POST a form
> via AJAX.
> I'm sure it is easy (as most prototype.js function calls are) but
> how ?
>
> I want the reply to update the div that holds the form (which itself
> was downloaded via AJAX).
> bill
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to