0

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
    });
});

--

enter image description here

{"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'

victorf
  • 978
  • 2
  • 17
  • 35

1 Answers1

2

Inexplicably, but surely, my client-side form validation, powered by jQuery Validate Plugin, is causing it.

/* JS */
$(document).ready(function(){

    /* validation stuff -> ACTUALLY IT IS: */  
    $('form[name=formEnviarHistorico]').validate(validacaoHistorico);
    /* It is jQuery Validate plugin!!! */

    $('#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
    });
});

I just created a IF condition to avoid this validation line if user browser is IE9 or older and it runs finely. For now, my validation is being made only on server-side.

victorf
  • 978
  • 2
  • 17
  • 35
  • IMHO, it could happen because jQuery Validate Plugin have some issue with IE9 or older or even some issue about my jQuery version (1.10.3). Any ideas? – victorf Aug 11 '15 at 19:26
  • In fact, there are some possibilities already verified [here](http://stackoverflow.com/questions/15006185/jquery-validate-plugin-fails-in-ie) and [here](http://stackoverflow.com/questions/5942327/jquery-validation-not-working-in-ie7-ie8). – victorf Aug 13 '15 at 12:14