Wondering is there a function in javascript without jquery or any framework that allows me to serialize the form and access the serialize version?
相关问题
- Is there a limit to how many levels you can nest i
- Laravel Option Select - Default Issue
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
I started with the answer from Johndave Decano.
This should fix a few of the issues mentioned in replies to his function.
Button types will still be ignored if they don't have a name value.
This is how I am currently using this function.
I refactored TibTibs answer into something that's much clearer to read. It is a bit longer because of the 80 character width and a few comments.
Additionally, it ignores blank field names and blank values.
Here is pure JavaScript approach:
Though it seems to be working only for POST requests.
https://developer.mozilla.org/en-US/docs/Web/API/FormData
If you target browsers that support the
URLSearchParams
API (all recent browsers), use this:Otherwise, use this one-liner (works everywhere except IE):
I've grabbed the entries() method of formData from @moison answer and from MDN it's said that :
but the only issue is that mobile browser (android and safari are not supported ) and IE and Safari desktop too
but basically here is my approach :
the code can be found here