aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Creating multipart request using Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Creating multipart request using Javascript" Watch "Creating multipart request using Javascript" New topic
Author

Creating multipart request using Javascript

Tushar Madhukar
Ranch Hand

Joined: May 03, 2006
Posts: 36
Hi,

Can I create a multipart request using Javascript?

I need to create a multipart request where one part has content-type "application/x-www-form-urlencoded" and contains data in name/value pairs (just like query string in GET requests). The other part has content-type "text/xml" and contains an XML document.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

You don't build requests of any kind in JavaScript. The browser does if for you when you submit a form, click a link, redirect to a link, or generate an Ajax request.

What is it that you are really trying to accomplish that can't be handled by a multipart form?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tushar Madhukar
Ranch Hand

Joined: May 03, 2006
Posts: 36
I have a form, which contains several text boxes (for username, password and other things related to my app). Additionally, there is a text area where a user can enter an app-specfic XML. If I set the "enctype" attribute of the form to "multipart/form-data", each of the values entered by the user go into a separate part of the multipart request.

Instead of this, I need the browser to create a multipart request that contains only two part: one part contains the user credentials in name/value pairs, clubbed together using '&' as in query string (say, username=max&password=f245f&...). The other part should contain the XML string.

Since I wasn't able to do this using just the enctype/encoding attributes, I was wondering if Javascript could be used to construct this kind of a request.

Regards
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

No, JavaScript will not help you.

But why the need to try and change what the browser will submit? Just write your server-side code properly to digest what the browser submits. That's what everyone else does. Why do you need something different?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Creating multipart request using Javascript