473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Faking a form submission

Good morning,

Is there a good way to use JavaScript to send a form submission, but get
back the response as a string, rather than loading it into a page? I
could write the code to send the submission via XMLHttpRequest, but that
seems hard... especially implementing multipart-encoded form submission
such as required for file upload.

Ideas?

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 23 '05 #1
3 1888
Chris Smith wrote:
Good morning,

Is there a good way to use JavaScript to send a form submission, but get
back the response as a string, rather than loading it into a page? I
could write the code to send the submission via XMLHttpRequest, but that
seems hard... especially implementing multipart-encoded form submission
such as required for file upload.

Ideas?

You might want to have a look at kupu (SVN checkout from
http://codespeak.net/svn/kupu/trunk/kupu) and search for kupu_upload_form.

The form there has a target attribute and is followed by an invisible
iframe with a name matching the target. When the form is submitted, this
means the response comes back into the iframe. The response includes an
onLoad event which calls a javascript method back in the main document to
handle the result or display an error message.
Jul 23 '05 #2
Duncan Booth <du**********@invalid.invalid> wrote:
You might want to have a look at kupu (SVN checkout from
http://codespeak.net/svn/kupu/trunk/kupu) and search for kupu_upload_form.

The form there has a target attribute and is followed by an invisible
iframe with a name matching the target. When the form is submitted, this
means the response comes back into the iframe. The response includes an
onLoad event which calls a javascript method back in the main document to
handle the result or display an error message.


That would work... except that I don't have any control over the form
tag... and the form needs to work as usual when the real submit button
is pressed. I suppose I could temporarily set the target via DOM, and
then put it back after the Form.submit() call... seems kinda kludgy,
though. I'm debating whether that's cleaner than faking the form submit
via XMLHttpRequest.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 23 '05 #3
Chris Smith wrote:
Duncan Booth <du**********@invalid.invalid> wrote:
You might want to have a look at kupu (SVN checkout from
http://codespeak.net/svn/kupu/trunk/kupu) and search for
kupu_upload_form.

The form there has a target attribute and is followed by an invisible
iframe with a name matching the target. When the form is submitted,
this means the response comes back into the iframe. The response
includes an onLoad event which calls a javascript method back in the
main document to handle the result or display an error message.


That would work... except that I don't have any control over the form
tag... and the form needs to work as usual when the real submit button
is pressed. I suppose I could temporarily set the target via DOM, and
then put it back after the Form.submit() call... seems kinda kludgy,
though. I'm debating whether that's cleaner than faking the form
submit via XMLHttpRequest.

You may not have to put it back immediately: you just need an onsubmit
handler which works out which way you want to submit the form and direct
the target accordingly.

Alternatively clone the entire form and set the target on the clone. I have
no idea whether you can then submit the clone without adding it into the
DOM. If you can then that would be a nice solution, one call to cloneNode,
set the target and submit.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Tom | last post by:
I have created the following code for a product select/payment form (don't know if there is a better way) and I have been trying to make the following changes (unsuccessfully so far): 1) ...
19
by: Pete | last post by:
I have form/select which executes a function using onchange. No problem. However, when I validate the page with a strict HTML 4.01 doctype at http://validator.w3.org, it demands either an action or...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
2
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
3
by: | last post by:
I am working on a web/webservice application that has a service layer. Most service methods will perform an access-check before executing. This check uses the IPrincipal credentials available in...
8
by: yawnmoth | last post by:
Say I have the following HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body> <form action="">
6
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and...
1
by: Homer | last post by:
Hi, I just got a requirement from my HR department to automate their form submission process and integrate it into the Intranet project that I had just completed Phase 1 of. Because of the...
8
Megalog
by: Megalog | last post by:
Hey guys.. my turn to ask a question: I'm having a weird issue with a form I've reworked. This form has a combo box, which when used is changing the recordsource of a subform. This subform has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.