I need to submit a FormData object via ajax, but the preXhr event does not allow me to return data
I need to submit a FormData object via ajax, but the preXhr event does not allow me to return data
I am trying to submit form data via a FormData object when data table posts it's ajax request. To do this, I am handling the datatables preXhr event. Unfortunately, this event allows me to modify the data object passed to it, but it does not allow me to return a new data object. Since a FormData object is not inspectable, I cannot copy its data into this pre-existing object. It would be nice if I could simply return the FormData object and have it use that for the request. Is there any way around this problem?
Answers
I just noticed the "settings" parameter. Can I just override the "data" parameter there?
No, I cannot. It caches the object referenced passed to the function, so setting settings.data has no effect. Is there really no way to define the root data object passed to the ajax call with DataTables?
Hi,
At the moment, the only way to do this would be use use
ajax
as a function and make your own Ajax call. Its not as bad as it might first sound, just a few lines of code will do it.I think this is the first time I've been asked about using
FormData
with the Ajax data options - it does make a lot of sense and I'll explore that for future versions. Thanks for bringing it up.Allan