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

POST with application/json #3144

Open
Aduen opened this issue Jan 24, 2025 · 1 comment
Open

POST with application/json #3144

Aduen opened this issue Jan 24, 2025 · 1 comment

Comments

@Aduen
Copy link

Aduen commented Jan 24, 2025

Why is this impossible:
<div hx-post="/update" hx-trigger='click' hx-vals='{"hello": [1,2,3], "world": {"beta": [1,2,3], "alpha": 1}}' hx-headers='{"Content-Type": "application/json"}' hx-encoding="application/json">Update</div>

It seems that a simple POST with a slightly complex JSON payload should not be this hard or am I missing something?

I have tried the hx-ext="json-enc-custom" but that doesn't seem to target this use-case.

@Aduen
Copy link
Author

Aduen commented Jan 24, 2025

Narrowed it down to a certain JSON structure with hx-ext="json-enc" and hx-vals='{"hello": [1,2,3]}'
Causes:
TypeError: Converting circular structure to JSON --> starting at object with constructor 'Array' --- index 3 closes the circle

JSON.parse('{"hello": [1,2,3]}') works as intended
JSON.stringify({"hello": [1,2,3]}) works as intended

hx-vals='{"hello": {"world": [1,2,3]}}'
no issues

It seems that having an array in the first element causes problems. Workaround: hx-vals={"data": {_the actual object_}}

Feels like unintended behavior

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