Question

How do I use FormData from a JavaScript Code Module?

new FormData();

gives:

FormData is not defined

Was it helpful?

Solution

Because JavaScript Code Modules do not have a normal browser context, I sometimes get around this by passing in a window, document, or whatever object might pertain to what I needed (e.g., passing in the window or FormData object when you invoke a method built inside your module).

However, I see this concern has already been raised by someone and there is a way around it: https://bugzilla.mozilla.org/show_bug.cgi?id=672690#c4

var formData = Components.classes["@mozilla.org/files/formdata;1"]
                         .createInstance(Components.interfaces.nsIDOMFormData);

I believe you can always find such class/interface equivalents of browser context items, unless you need to grab a specific window or document.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top