error handler isn't called when file is uploaded via ajax using jQuery form plugin
Posted
by scompt.com
on Stack Overflow
See other posts from Stack Overflow
or by scompt.com
Published on 2010-05-13T12:06:56Z
Indexed on
2010/05/13
14:24 UTC
Read the original article
Hit count: 367
Here's my test case. If the form is posted, a 500 error response is sent. If not, the form is sent.
If the file input tag is commented out, the error handler is called. If the file input tag is present, the error handler isn't called. I think this might have something to do with the fact that jQuery needs to use an iframe to handle the upload and iframes don't seem to respond to the error handler.
Edit:
If I add iframe: true
to the options passed to ajaxSubmit
to force the use of an iframe, the non-file-upload case stops working also, so it definitely has to do with the iframe.
Edit2: I'm using the jQuery Form Plugin.
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
header('HTTP/1.1 500 Internal Server Error');
die;
} else {?>
<html><head>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=2.9.2'></script>
<script type='text/javascript' src='http://github.com/malsup/form/raw/master/jquery.form.js?v2.43'></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('a').click(function() {jQuery('form').ajaxSubmit({error: function(){alert('error handler called');}})});
});
</script>
</head><body>
<form method="POST">
<input type="text" name="mytext" />
<input type="file" name="myfile" /><!-- comment this element out -->
<input type="hidden" name="blah" value="blah" />
<a>submit</a>
</form>
</body></html>
<?php }
Is there any way to get the error handler to be called in both situations?
© Stack Overflow or respective owner