Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Submit a form in the background

Reply
Thread Tools

Submit a form in the background

 
 
Christoph
Guest
Posts: n/a
 
      12-11-2007
I have an HTML form that I would like to submit without reloading the
page. I know how to go about this technically - attach a function to
the submit button's onclick event that builds an HttpRequest, sends it
and blocks the form from submitting in the normal fashion.

But building the request body from the form elements is a real bother.
So far most of these forms have had only one or two fields which were
easily stuck together manually, but now I have a file upload field
that complicates things.

Is there some kind of document.getElementById('formID').buildRequest()
function that builds the request the way the browser normally would,
but returns it as a string instead of sending it to the server? It's
hard to believe that all Ajax forms out there cobble together a query
string from the values of each of their individual fields...

--
Christoph
 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      12-11-2007
On Dec 11, 5:31 pm, Christoph <christoph.bursc...@gmail.com> wrote:
> but now I have a file upload field
> that complicates things.


It doesn't complicate: it simply eliminates the XmlHttpRequest out of
options - it has no access to type=file fields so it's not able to
submit them. So use more universal and reliable way with hidden target
iframe as already suggested.

For form w/o type=file fields you still can use XmlHttpRequest-based
libraries like from www.ajaxtoolbox.com - they can handle forms of any
complexity.

 
Reply With Quote
 
 
 
 
Ian Hobson
Guest
Posts: n/a
 
      12-12-2007
Christoph wrote:
> I have an HTML form that I would like to submit without reloading the
> page. I know how to go about this technically - attach a function to
> the submit button's onclick event that builds an HttpRequest, sends it
> and blocks the form from submitting in the normal fashion.
>
> But building the request body from the form elements is a real bother.
> So far most of these forms have had only one or two fields which were
> easily stuck together manually, but now I have a file upload field
> that complicates things.
>
> Is there some kind of document.getElementById('formID').buildRequest()
> function that builds the request the way the browser normally would,
> but returns it as a string instead of sending it to the server? It's
> hard to believe that all Ajax forms out there cobble together a query
> string from the values of each of their individual fields...
>
> --
> Christoph


Your solution is to have the script that handles your post return a 200
reply with no content.

This will leave the old page displaying on the screen.

NB - Only tested in IE6 and Firefox.

Regards

Ian

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert form to submit on load instead of clicking submit button? Network-Man HTML 5 07-07-2012 12:06 PM
submit 1 form to 2 servers or 2 forms to 2 server (1 form each) on 1 submit abansal.itp@gmail.com Javascript 3 06-23-2007 07:29 AM
Forms with multiple submit buttons vs 'form' objects with single 'submit' methods neil.fitzgerald@ic.ac.uk Python 4 04-14-2006 04:58 PM
submit the form data to the popup window without a submit button jrefactors@hotmail.com HTML 2 01-01-2005 06:07 AM
Form submit - hitting enter does not trigger Submit button ASP General 2 10-25-2004 03:37 PM



Advertisments