Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
98
rated 0 times [  102] [ 4]  / answers: 1 / hits: 18779  / 12 Years ago, thu, february 14, 2013, 12:00:00

I need to read data from FormData? I try to read something like someFormatData[valueName] but it not working.
options[fileId] or options[file] does not work. Also I try options.fileId same result:



function upload(file, fileId, callback) {
var formData = new FormData();
formData.append(file, file);
formData.append(fileID, fileId);

$.ajax({
url: '/url',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
callback(response);
}
});
}


asyncTest(test upload chunk, function() {
var blob = new Blob([Hello world!], { type: text/plain }),
options = null,
fileID =someFileID,
response;

jQuery.ajax = function(param) {
options = param; // THIS is FormData object
// how to read fileId and file from here
};

upload(blob, fileID, function (data) {
response = data;
});

options.success({
someProp: 'responseFromServer'
});

setTimeout(function() {
QUnit.equal(options, dataTosend, parameters is OK);
QUnit.equal(response[someProp], responseFromServer, Response ok);
start();
},1000);
});

More From » qunit

 Answers
9

If you take your FormData object you can use a few different methods on it… What you are looking for is



formData.get()


or



formData.getAll()


https://developer.mozilla.org/en-US/docs/Web/API/FormData



Note that the get() method is not fully supported on all browsers.


[#80221] Wednesday, February 13, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rossthomasn

Total Points: 122
Total Questions: 78
Total Answers: 105

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
;