I've been developing an application which must submit a form with a file upload field in two distinct situations. Both situations, in this same application, work perfectly in Firefox and Chrome, but one of this situations fails when we run it on IE.
SITUATION #1 (it works perfectly in FF, Chrome, IE9-7):
/* controller */
def salvarArquivo() {
/* service calls, etc */
uploadStatusJSON = uploadStatus as JSON
render uploadStatusJSON.toString()
}
--
/* JS - I'm using ajaxForm plugin by [malsup][1] */
$('#formularioEnviarArquivo').ajaxForm({
beforeSubmit: validateFileUploadForm,
clearForm : true,
dataType : 'text',
success : function(dataStr) {
var dataObj = $.parseJSON(dataStr);
if (dataObj.status == false) {
/* do this */
} else {
/* do that */
}
}
});
It returns a right JSON-text, which is parsed as an JS object and the JS code processes it rightly and I have a nice page with a nice UX
SITUATION #2 (it fails in IE9 or older):
/* controller */
def salvarComentarioAjax(){
/* service, queries, etc
* ask me more details */
def historicoJSON = historico as JSON
render historicoJSON.toString()
} // end method
--
/* JS */
$(document).ready(function(){
/* validation stuff */
$('#formEnviarHistorico').ajaxForm({
beforeSubmit : function(){
$('#submitFile').button('loading');
},
clearForm : true,
dataType : 'text',
success : function(dataStr){
var data = $.parseJSON(dataStr);
if(data.status == false){
/* do this */
}else{
/* do that */
}
} // end success
});
});
--
{"status":true,"comentario":"teste","arquivos":[{"status":true,"nome":"Hydrangeas.jpg","caminho":"http://192.168.0.81:8080/vs3/arq/atendimentos/20150811111634517_224442_Hydrangeas.jpg","mensagem":"OK"}],"nomeUsuario":"CINTIA BERNARDI","confidencial":false,"dataCadastro":"2015-08-11T14:16:34Z","id":251769,"foto":{"img":{"FD":{"class":"java.io.FileDescriptor"},"channel":{"class":"sun.nio.ch.FileChannelImpl","open":true},"class":"java.io.FileInputStream"},"path":"images/img_perfil/4a94303760487537892d8af0b5c47642.jpg","nomeFoto":"4a94303760487537892d8af0b5c47642.jpg"}}
What could I verify? Anything else? I've been reading a lot of recommendations about setting contentType as 'text/plain'
and so on, but probably I've tried all them, setting ajax's dataType as 'text'
or as 'json'