samedi 9 mai 2015

formData doesn't work after getting the page with POST

I some a strange problem, when I acess to the page (with code to upload image) by GET method, everything works great. But when I access to the page with the POST method, server receive empty data.

Code:

/* ... */
var files = e.dataTransfer.files;
checkSize(files, function(s, n){
    if(s){
        var data = new FormData();
        data.append('_method', 'upload');

        $.each(files, function(k, v){
            data.append(k, v)
    });
    upload(el, data, m)
}

I think that the problem is in the upper code, buthere is the upload code:

$.ajax({
    url : $(el).parent().attr('action'),
    type: 'POST',
    data: data,
    cache: false,
    dataType:false,
    processData: false,
    contentType: false,
    success: function(data, textStatus, jqXHR){
        /* ... */
    },
    error: function(jqXHR, exception){
        /* ...*/
    }
});

Server is on nodeJs, so here is an result of receiving data after GET method:

body:
{ _method: 'upload' }
files:
{ '0':
   { fieldName: '0',
     originalFilename: 'LAYOUT.png',
     path: 'C:\\Users\\Ivan\\AppData\\Local\\Temp\\5776-1hdql6r.png',
     headers:
      { 'content-disposition': 'form-data; name="0"; filename="LAYOUT.png"',
        'content-type': 'image/png' },
     ws:
      { _writableState: [Object],
        writable: true,
        domain: null,
        _events: [Object],
        _maxListeners: 10,
        path: 'C:\\Users\\Ivan\\AppData\\Local\\Temp\\5776-1hdql6r.png',
        fd: null,
        flags: 'w',
        mode: 438,
        start: undefined,
        pos: undefined,
        bytesWritten: 349600,
        closed: true },
     size: 349600,
     name: 'LAYOUT.png',
     type: 'image/png' } }

And here, data after POST method:

body:
{ req_type: '' }
files:
undefined

Aucun commentaire:

Enregistrer un commentaire