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

[Suggestions] Add a new serialization for Html To JSON #2091

Closed
ghost opened this issue Feb 14, 2015 · 6 comments
Closed

[Suggestions] Add a new serialization for Html To JSON #2091

ghost opened this issue Feb 14, 2015 · 6 comments

Comments

@ghost
Copy link

ghost commented Feb 14, 2015

Hello all:

It would be nice if I can use JSON formation data to pass where I use $.ajax…….

I found there were lots of functions extended from jQuery. However, none of them satisfies me because it lacks many functions, I searched for many times on the net, no results. Even I use $.serializeArray(), that doesn't meet my needs.

I hope this function can:

  1. Either serialize "form" or none "form" Html tags——I mean any tag with "input" types should be serialized to JSON.
    2) For radio button tags with the same name, it should ONLY serialize the choosen one.
    3) For checkbox button tags with the same name, it should return me an array with the choosen multiple values (even none is choosen, make the empty array left).
    4) For the table tag, we should offer customers one choice——isEachRowSeralized. This is a boolean value that indicates whether we need serialize each row as an JSON object, or just serialize the whole table's input values as usual.
    Notice for Point 4——NOT ONLY FOR TABLE tag, but other familiar tags as well.
@ghost ghost changed the title [Suggestions] Add an "HtmlToJson" function [Suggestions] Add a new serialization for Html To JSON Feb 14, 2015
@dmethvin
Copy link
Member

This seems like a good idea for a plugin. It wouldn't go into jQuery core.

@formula1
Copy link

Originally I was going to write an angry rant about how this was dismissed. Here are some facts.

Form <-> Object

Turning form data into json is common practice and the opposite isn't that uncommon though generally reserved for parsing the current search query and populating the search form

Form <-> QueryString

jQuery has a serialize function however has no deserialize function. Luckilly there are plugins out there. But it's debatable why serialize would even be in jQuery core if you can't shift something back.

QueryString <-> JSON Object

Turning a serialized String into an object and back can be done by numerous libraries

Why should jquery care?

jQuery is a mix of useful wrappers to avoid browser differences as well as make your life easier. Why is there an animate function?-Because animations are one of the things that really made jQuery popular. Why is there a data function?-Because you can store objects by reference. Why is jQuery still using it's own deferred system instead of Bluebird?-because done makes more sense than then in many cases. If forms weren't part of of the dom, you would be right. However forms are an important peice of the dom, arguably the most important. And to brush off supporting it as a finge usecase seems quite shortsighted

@ghost
Copy link
Author

ghost commented Mar 21, 2015

@dmethvin

Maybe the jQuery's size is a bit too large..... However these functions areTOO important for us and it is frequently used. So for the jQuery's official side, it would be better to offer this;)

@formula1
Copy link

I would argue if jQueries size is getting too large. Perhaps effects/css need to be moved to a seperate repository. Cross browser compatability for css has also been a huge issue and creating an effective animation suite is not task that wouldn't involve alot of code.

However that is a huge change and likely to be in the complete wrong direction as what they want to be

@dmethvin
Copy link
Member

@formula1
Copy link

  • Does $.ajax need jQuery internals or is it just a wrapper? I believe it's just a wrapper.
  • Of course it can benefit. But then again, code can always benefit from features. Nowadays jQuery is attempting to be lean and mean. Internally It most likely cannot as it is a tool for developers. However, it relates a lot to .val() and assorted inputs.
  • Are forms a part of the dom? I believe they are.
  • all of these are served by a plugin's, however As seen in this comment (Though from 2011 it still ranks high on search results for "stackoverflow deserialize jQuery") people would generally prefer recreating (a possibly sloppy and/or imperfect) implementation than use a plugin. There can be many reasons, however it comes down to "official" vs "unofficial". Unless it's a giant library or a force to be reckoned with, usually simple scripts are seen as untrustworthy/annoying as you end up have 10 to 15 small files just to get basic functionality. Another example is here which ends up being number 2 for jQuery deserialize. Does jQuery want to support developers recreating a possibly worse wheel? I think that's the point of jQuery, has all the crossbrowser/tools you would use everywhere
  • Does it change Existing Api? I don't believe it does.

I fail to see why something like deserialized or serializeObject doesn't make the cut. For what it's worth, you guys make an excellent product and I'd rather praise than criticize. However, I don't enjoy 1 line answers

@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants