Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amplify.js incompatible with FormData #107

Open
devconcept opened this issue Jan 15, 2015 · 0 comments
Open

amplify.js incompatible with FormData #107

devconcept opened this issue Jan 15, 2015 · 0 comments

Comments

@devconcept
Copy link

In a recent work I had to write an application that send files using ajax. In jQuery the syntax was

$.ajax({
   url: formURL,
   type: 'POST',
   data: formData,
   contentType: false,
   cache: false,
   processData: false,
   success: ...,
   error: ...
});

On amplify.js it just did'n work. No matter what the options were. After some debbuging I found that the FormData object passed was turned to a regular javascript object after the ajax preprocess message was executed and then passed to jQuery. The library already added an exception in case the object passed were a string so I just add another exception so the object were ignored if was a native FormData object.

amplify.subscribe( "request.ajax.preprocess", function(defnSettings, settings, ajaxSettings) {
        var mappedKeys = [],
            data = ajaxSettings.data;

        if (typeof data === "string" || Object.prototype.toString.call(data) === "[object FormData]") {
            return;
        }
......(omited)
)}

Maybe you can check for constructor or perform some other work so I share the solution as well so you can improve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant