[jQuery] File upload - json result ERRORZ!

[jQuery] File upload - json result ERRORZ!


There appears to be some sort of bug happening if you do a file upload
and try to return a json result. If you submit this page without any
file selected in the file input an alertbox will pop up saying:
{"data":"<div>"}
however if you select a file in the file input then press submit the
alert will show this:
{"data":"<div>"}</div>
which can't be eval'd correctly as a json object. It looks like the
browser is trying to auto-complete the
object returned in the iframe or something like that? Testing was done
in FF3.5.3
<?php
    if ( !empty($_POST) ) {
        echo json_encode(array('data'=>'<div>'));
        exit;
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript" src="http://malsup.com/jquery/form/
jquery.form.js?2.33"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#frm').ajaxForm({success: function(data) { alert( data ); }});
    });
</script>
</head>
<body>
    <form name='frm' id='frm' method='post' action='' enctype="multipart/
form-data">
        

File: <input type='file' name='file' />


        <input name='btnSubmit' type='submit' value='submit' />
    </form>
</body>
</html>