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

AJAX with zero form fields does not send Content-Type header #5346

Open
mvorisek opened this issue Oct 12, 2023 · 1 comment
Open

AJAX with zero form fields does not send Content-Type header #5346

mvorisek opened this issue Oct 12, 2023 · 1 comment

Comments

@mvorisek
Copy link

mvorisek commented Oct 12, 2023

see fomantic/Fomantic-UI#2926 issue and related discussion

Request Content-Type is/can be used by a webserver to determine the request type [1].

  • Array/form data should always send Content-Type. Data of value "empty array" must send the header the same way as non-empty array data. This is also behaviour of native html form /wo any fields [2].

  • non-array data ("null"/"undefined"/"false") can/should (probably) continue to send no Content-Type header implicitly

the LoC/condition to fix: https://github.com/jquery/jquery/blob/3.7.1/src/ajax.js#L638

[1] example https://github.com/Nyholm/psr7-server/blob/1.0.2/src/ServerRequestCreator.php#L62
[2] <form action="/p.aspx" method="post"><input type="submit"></form>

@mvorisek mvorisek changed the title [API] serializeForm with no form fields does not send Content-Type header AJAX with no form fields does not send Content-Type header Oct 12, 2023
@mvorisek mvorisek changed the title AJAX with no form fields does not send Content-Type header AJAX with zero form fields does not send Content-Type header Oct 12, 2023
@mgol mgol added Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. Ajax labels Oct 30, 2023
@timmywil
Copy link
Member

timmywil commented Nov 6, 2023

Thanks for opening an issue. It'd be helpful if you could create a reduced test case (possibly using httpbin.org) and we can see if the behavior for your use case (1) is intended and (2) can be changed. A call to $.ajax may be too late in the process to determine the correct header, so setting it explicitly is probably still the best option.

@timmywil timmywil added Needs info and removed Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants