miguel-perez/smoothState.js

Suggestion : enhance plugin with file upload support

Open

#217 aberto em 19 de set. de 2015

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)CSS (515 forks)batch import
enhancementhelp wanted

Métricas do repositório

Stars
 (4.433 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

For my project I added some lines to support file upload: . first check if 'FormData' is supported . if supported : use specific request definition (contentType has to be set to 'false') . if not supported : use original request definition (contentType can not be set to 'false')

if(typeof FormData === 'function'){
    // file upload supported
    var request = {
        url: $form.prop('action'),
        data: new FormData($form[0]),
        type: $form.prop('method'),
        async: false,
        cache: false,
        contentType: false,
        enctype: 'multipart/form-data',
        processData: false
    };
}else{
    // file upload not supported
    var request = {
        url: $form.prop('action'),
        data: $form.serialize(),
        type: $form.prop('method')
    };
}

If someone is aware of existing issues for this implementation, I would be glad to hear.

Guia do colaborador