How to correctly set response for actions #12725
-
I have a form on
But why on the front-end, when I log the result by:
The result looks so weird like this:
What I expect is as simple as the same structure and format in the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The data is serialized using Form actions are meant to be used with forms, which will work even if JS fails to load. They can be progressively enhanced so no additional page reload is required if JS loaded. The If you need to use the action directly regardless, SvelteKit provides a function you can use to deserialize the data. import { deserialize } from '$app/forms'; const result: ActionResult = deserialize(await response.text()); |
Beta Was this translation helpful? Give feedback.
The data is serialized using
devalue
, which is a more powerful serializer than the built-in one.Form actions are meant to be used with forms, which will work even if JS fails to load. They can be progressively enhanced so no additional page reload is required if JS loaded. The
enhance
action can also be used to attach additional logic to the form submission. I would recommend using this.If you need to use the action directly regardless, SvelteKit provides a function you can use to deserialize the data.