MoOx / pjax

Easily enable fast Ajax navigation on any website (using pushState + xhr)
MIT License
1.43k stars 124 forks source link

Forms with enctype set as multipart/form-data get submited with the default application/x-www-form-urlencoded #168

Closed davidSocast closed 6 years ago

davidSocast commented 6 years ago

Hi guys, i've been struggling with something that i believe is a bug on this excellent library:

From the previous threads and the documentation, my understanding was that forms submitted through pjax are submitted with a content type set to "application/x-www-form-urlencoded".

However, if the form has a enctype set to "multipart/form-data", the pjax call is supposed to use this value and set the header Content-Type to this value.

I can't make it work on my server (Apache/PHP7) and despite the required enctype my data are sent as "application/x-www-form-urlencoded".

the formData is set properly, and using the debug mode, i can see that the reight object is used to pass the form data to my backend.

But when i look to the post request, the content-type is not changed, so my PHP script cannot handle the data properly.

find a the following capture describing what i believe is an issue : image image image image

robinnorth commented 6 years ago

Hi @davidSocast, thanks for reporting this. Yes, looks like this is a bug as the Content-Type header is currently always set to "application/x-www-form-urlencoded" when submitting a form:

https://github.com/MoOx/pjax/blob/e49d8947f7ca00254d09920784bcf8a3e4e16f2d/lib/send-request.js#L70-L73

We'll look to fix this in the next release of the library.

BehindTheMath commented 6 years ago

The fix for this should be simple: just add && !formData to the if statement. However, when I started writing tests for this, I ran into what I think is a bug in jsdom. So I'm going to wait until that's resolved to work on this.

BehindTheMath commented 6 years ago

The issue I opened in jsdom has not had a response in 3 weeks, so I'm submitting the fix for this, and the tests will have to wait.