By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,967 Members | 2,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,967 IT Pros & Developers. It's quick & easy.

ajax multipart problem

P: n/a
Hello,

I'm trying to use AJAX to send multipart data (not from a client
file), and I'm using a requestbody with the files separated by a
boundary, like that:

var boundStr = 'capitano';
var boundary = '--' + boundStr;

var requestbody = [
boundary,
'Content-Disposition: file; name="htmlfile";
filename="hello.html"',
'Content-Type: text/html',
'',
'<html>some file</html>,
boundary,
'Content-Disposition: form-data; name="jdk_version"',
'',
jdkVersion,
boundary
].join('\n');

And then I set the headers and send, like that:

httpRequest.onreadystatechange = requestdone;
httpRequest.open('POST', url, true);
httpRequest.setRequestHeader('Content-type', 'multipart/form-
data; boundary="' + boundStr + '"');
httpRequest.send(requestbody);

Now when I try to send the request, I get an error "File not found" in
Firefox, "Resource not found" in IE. But I'm not reading a file?? I'm
puzzled.

Any ideas welcome.

May 18 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On May 18, 9:46 am, charles <char...@boisvert.me.ukwrote:
Hello,

I'm trying to use AJAX to send multipart data (not from a client
var boundStr = 'capitano';
var boundary = '--' + boundStr;

var requestbody = [
boundary,
'Content-Disposition: file; name="htmlfile";
filename="hello.html"',
'Content-Type: text/html',
'',
'<html>some file</html>,
boundary,
'Content-Disposition: form-data; name="jdk_version"',
'',
jdkVersion,
boundary
].join('\n');

And then I set the headers and send, like that:

httpRequest.onreadystatechange = requestdone;
httpRequest.open('POST', url, true);
httpRequest.setRequestHeader('Content-type', 'multipart/form-
data; boundary="' + boundStr + '"');
httpRequest.send(requestbody);

Now when I try to send the request, I get an error "File not found" in
Firefox, "Resource not found" in IE. But I'm not reading a file?? I'm
puzzled.

Any ideas welcome.
Works for me. Can you post the text of the error as listed the
JavaScript console?

May 20 '07 #2

P: n/a
On 20 mai, 19:18, "Skye Shaw!@#$" <skye.s...@gmail.comwrote:
On May 18, 9:46 am, charles <char...@boisvert.me.ukwrote:
Hello,
I'm trying to useAJAXto sendmultipartdata (not from a client
var boundStr = 'capitano';
var boundary = '--' + boundStr;
var requestbody = [
boundary,
'Content-Disposition: file; name="htmlfile";
filename="hello.html"',
'Content-Type: text/html',
'',
'<html>some file</html>,
boundary,
'Content-Disposition: form-data; name="jdk_version"',
'',
jdkVersion,
boundary
].join('\n');
And then I set the headers and send, like that:
httpRequest.onreadystatechange = requestdone;
httpRequest.open('POST', url, true);
httpRequest.setRequestHeader('Content-type', 'multipart/form-
data; boundary="' + boundStr + '"');
httpRequest.send(requestbody);
Now when I try to send the request, I get an error "File not found" in
Firefox, "Resource not found" in IE. But I'm not reading a file?? I'm
puzzled.
Any ideas welcome.

Works for me. Can you post the text of the error as listed the
JavaScript console?
Firefox:

Error: uncaught exception: [Exception... "Component returned failure
code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]"
nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS
frame :: file:///C:/charles/compile.html :: <TOP_LEVEL:: line 39"
data: no]
May 20 '07 #3

P: n/a
On May 20, 2:44 pm, charles <char...@boisvert.me.ukwrote:
On 20 mai, 19:18, "SkyeShaw!@#$" <skye.s...@gmail.comwrote:
On May 18, 9:46 am, charles <char...@boisvert.me.ukwrote:
Hello,
I'm trying to useAJAXto sendmultipartdata (not from a client
var boundStr = 'capitano';
var boundary = '--' + boundStr;
var requestbody = [
boundary,
'Content-Disposition: file; name="htmlfile";
filename="hello.html"',
'Content-Type: text/html',
'',
'<html>some file</html>,
boundary,
'Content-Disposition: form-data; name="jdk_version"',
'',
jdkVersion,
boundary
].join('\n');
And then I set the headers and send, like that:
httpRequest.onreadystatechange = requestdone;
httpRequest.open('POST', url, true);
httpRequest.setRequestHeader('Content-type', 'multipart/form-
data; boundary="' + boundStr + '"');
httpRequest.send(requestbody);
Now when I try to send the request, I get an error "File not found" in
Firefox, "Resource not found" in IE. But I'm not reading a file?? I'm
puzzled.
Any ideas welcome.
Works for me. Can you post the text of the error as listed the
JavaScript console?

Firefox:

Error: uncaught exception: [Exception... "Component returned failure
code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]"
nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS
frame :: file:///C:/charles/compile.html :: <TOP_LEVEL:: line 39"
data: no]

You need to test this via a web server, as you are making a XML /Http/
Request.
May 21 '07 #4

P: n/a
var boundStr = 'capitano';
var boundary = '--' + boundStr;
var requestbody = [
boundary,
'Content-Disposition: file; name="htmlfile";
filename="hello.html"',
'Content-Type: text/html',
'',
'<html>some file</html>,
boundary,
'Content-Disposition: form-data; name="jdk_version"',
'',
jdkVersion,
boundary
].join('\n');
And then I set the headers and send, like that:
httpRequest.onreadystatechange = requestdone;
httpRequest.open('POST', url, true);
httpRequest.setRequestHeader('Content-type', 'multipart/form-
data; boundary="' + boundStr + '"');
httpRequest.send(requestbody);
charlesWhen I try to send the request, I get an error "File not
charlesfound" in Firefox, "Resource not found" in IE. But I'm not
charlesreading a file?? I'm puzzled.

shawWorks for me. Can you post the text of the error as listed the
shawJavaScript console?

charlesFirefox:
charlesError: uncaught exception: [Exception... "Component
charlesreturned failure code: 0x80520012
charles(NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]"
charlesnsresult: "0x80520012
charles(NS_ERROR_FILE_NOT_FOUND)" location: "JS
charlesframe :: file:///C:/charles/compile.html :: <TOP_LEVEL::
charlesline 39" data: no]

shawYou need to test this via a web server, as you are making a
shawXML /Http/ Request.

Oops... I thought it was enough to connect to a server. Thanks.

Charles
May 22 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.