It is so discreet that it is intended only for transferring data to an AJAX request and saves you from having to encode your data in "multipart / form-data" on your own, as is done when the form is submitted regularly, so you should use it only at the last moment, when you submit an AJAX request, rather than passing it to other functions.
Do it if you need access to the same data anywhwere else, you can just pass a simple JS object and write a simple helper, for example:
function createFormData(myData) { // It could also take an existing form for some values from the user var formData = new FormData(/** FormElement form */); for (var key in myData) { formData.append(key, myData[key]); } return formData; } sendMyInfo: function(params) // Add some data to the default params params.hash = this.S.Storage.get('h_token')); params.cacheBuster = (new Date()).valueOf(); // Inspect it console.log(myData); // Wherever you actually need FormData, create it for that purpose only.... var oReq = new XMLHttpRequest(); oReq.open("POST", "stash.php", true); oReq.send(createFormData(myData)); };
source share