javascript
从html表单内提取信息,如何从JavaScript中获取FormData中的数据?
我需要從FormData讀取數據嗎?我嘗試讀取someFormatData [“valueName”]之類的東西,但它不起作用.
options [“fileId”]或options [“file”]不起作用.我也嘗試了options.fileId相同的結果:
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);
});
總結
以上是生活随笔為你收集整理的从html表单内提取信息,如何从JavaScript中获取FormData中的数据?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 局域网络连接的计算机不全,WIN10局域
- 下一篇: 计算机专业可以用台式机吗,Win10X电