How to add header data in XMLHttpRequest when using formdata?

The Solution to How to add header data in XMLHttpRequest when using formdata? is


Your error

InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

appears because you must call setRequestHeader after calling open. Simply move your setRequestHeader line below your open line (but before send):

xmlhttp.open("POST", url);
xmlhttp.setRequestHeader("x-filename", photoId);
xmlhttp.send(formData);

~ Answered on 2013-10-29 15:15:03


Most Viewed Questions: