Hi all,
I'm trying to upload a form via jquery forms plugin. Here's the form:
-
<form method="post" action="<spring:url value="/grouplist/uploadavatar.do" />" enctype="multipart/form-data" id="formUploadAvatar">
-
<
table
width
=
"100%"
>
-
<
tr
>
-
<
td
width
=
"25%"
style
="
padding-top
:
30px
;
margin-top
:
30px
; "
>
-
<
spring:message
code
=
"usersettings.form.usersettings.avatar"
/>
-
</
td
>
-
<
td
style
="
padding-top
:
30px
;
margin-top
:
30px
;
vertical-align
:
middle
;"
>
-
<
div
id
=
"divImageAvatar"
style
="
display
:
none
"
><
img
id
=
"avatarImage"
width
=
"32"
height
=
"32"
align
=
"absmiddle"
/></
div
>
-
<
input
type
=
"file"
id
=
"createGroupPopupAvatar"
name
=
"avatar"
/>
-
<
input
type
=
"submit"
class
=
"button"
value
=
"
<
spring:message
code
=
"general.send"
/>
"
/>
-
<!-- <input type="button" class="button" value="<spring:message code="general.send"/>" onclick="javascript:sendAvatar()" /> -->
-
</
td
>
-
</
tr
>
-
</
table
>
-
</
form
>
The form contains a file upload field to upload an avatar, and a div with an image where to show the uploaded avatar. Here is the script I use to upload:
-
var uploadAvatarOptions = {
-
dataType:
'json'
,
-
success:
function
(data) {
-
if (data.code == 0) {
- // Show image using path contained in the data object
-
}
-
else
{
alert (data.description); // Error happened
-
}
-
}
-
};
-
$(document).ready(function() {
-
$(
'#formUploadAvatar'
).ajaxForm(uploadAvatarOptions);
-
});
This is the response sent from the server:
{"data":"/images/avfile.jpg","description":"","code":0}
This works fine in Firefox. However, in IE, the succedd callback contains null in the data parameter. I think this may be because Firefox sends the following headers on submit:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
The server, controlled by Spring, reacts sending a context type text/html
if I try the same in IE8 the headers sent are:
image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Spring, in turn, sends a response context type image/gif
So, my questions are, ¿how relevant is the response content type returned to process the data parameter as a json response? ¿is there any possibily to add request accept headers in IE environment? Perhaps the error is somewhere else, and it has nothind to do with headers...