JSON request failed with file upload

130 views
Skip to first unread message

mr.

unread,
Jul 11, 2008, 11:34:10 PM7/11/08
to MooTools Users
Here I have a normal form like this :

<form id="form" name="form" method="post" action="upload.php"
enctype="multipart/form-data">
<input type="file" size="20" name="handle" id="handle">
<input type='submit' name='submit' id='submit' value='Submit'>
</form>

Of course, it works fine but if I try :

<script type='text/javascript' src='mootools-1.2.js'></script>
<script>
window.addEvent('domready', function() {
$('submit').addEvent(
'click', function(e) {
e = new Event(e).stop();
var jsonRequest = new Request.JSON({onComplete: function(result){
alert(result.id);
}}).post($('form'));
}
);
});
</script>
<form id="form" name="form" method="post" action="upload.php"
enctype="multipart/form-data">
<input type="file" size="20" name="handle" id="handle">
<input type='submit' name='submit' id='submit' value='Submit'>
</form>

Then nothing happen but a strange message from FireBug :
[Exception... "Component returned failure code: 0x80070057
(NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult:
"0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame ::
javascript: eval(__firebugTemp__); :: anonymous :: line 1" data: no]

And in IE is :
Line: 3626
Char:3
Error: Invalid argument.
Code: 0

Can anybody tell me why please ? I'm really get stuck with it.

johnwait

unread,
Jul 12, 2008, 11:16:17 PM7/12/08
to MooTools Users
Most probably your server doesn't send back a valid JSON response.

mr.

unread,
Jul 13, 2008, 9:00:04 AM7/13/08
to MooTools Users
No, it's because that XHR does not support file upload so that any
<input type='file'> will be ignored >"< and I will have to use
<iframe> to handle file upload.

moussor

unread,
Jul 25, 2008, 10:37:05 AM7/25/08
to MooTools Users
Hi, i'm working on a form with file upload too (not with Request.JSON
but with Request.HTML) and I came to the same conclusion. That's a
bummer. Hopefully the Request class can be extended to allow file
uploads or as you said maybe an iframe is simpler but I have no idea
how to do that.

Jan Kassens

unread,
Jul 25, 2008, 1:57:59 PM7/25/08
to mootool...@googlegroups.com
XHR cant send files. There are some workarounds, but nothing built-in.
- using a hidden iframe where the form is submitted
- digitaralds FanzyUpload (digitarald.de) which uses Flash in the
background
- good old plain forms ;)

Jan

--
my blog: http://blog.kassens.net

Tim Lavelle

unread,
Jul 25, 2008, 2:07:11 PM7/25/08
to mootool...@googlegroups.com
That explains why my previous file uploads weren't working when I wasn't
using fancy upload.

TY

jeresch

unread,
Aug 10, 2008, 8:42:06 AM8/10/08
to MooTools Users
Hello,

I've the same problem with a file upload form which can't be handled
by Request.HTML.

How can I use an IFrame instead of Request.HTML to submit the form ?
The problem is that after submitting the form, I want to get out of
the IFrame with the datas sent by the form. Is it possible to do that
and how can it be done ?
Reply all
Reply to author
Forward
0 new messages