Side navigation
#9540 closed feature (wontfix)
Opened June 07, 2011 03:54PM UTC
Closed June 07, 2011 05:23PM UTC
Last modified June 08, 2011 01:32AM UTC
simplify form submissions
Reported by: | rasmus@mindplay.dk | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | ajax | Version: | 1.6.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
This pattern repeats in basically every jQuery application:
var form = $('form#foo'); $.post( form.prop('action'), form.serialize(), function (content) { // ... } );
Why don't we have something that simply uses the information already contained in the form tag? It already specifies the method (GET or POST), the URL (action) and we know we have to serialize the data on the form, so why not simply:
$('form#foo').send( function (content) { // ... } );
I prototyped a function that will do this here:
Attachments (0)
Change History (5)
Changed June 07, 2011 04:12PM UTC by comment:1
component: | unfiled → ajax |
---|
Changed June 07, 2011 04:30PM UTC by comment:2
priority: | undecided → low |
---|---|
type: | enhancement → feature |
I agree with ajpiano.
Changed June 07, 2011 05:23PM UTC by comment:3
resolution: | → wontfix |
---|---|
status: | new → closed |
ajpiano +1
Changed June 08, 2011 01:30AM UTC by comment:4
No sweat.
You make some interesting points, and it made me ponder and realize that I have a tendency to think that .post() should be enough for what I need - but it always eventually falls short. Because I'm lazy, I always try it first, but it never does what I want.
For one, when was the last time you found yourself needing to perform a post, but not needing to know whether it succeeded? This is so exotic, the only possible use case I can think of is insignificant stuff like news tickers or status updates. Even so, those would probably be GET rather than POST. How could you not need to handle errors? Never happens. Not where I'm from.
So it seems that I should be using $.ajax() - which also results in more semantic code, due to the named arguments. But also more redundancy.
So it occurs to me, what I need is actually a .ajax() function that wraps $.ajax() and completes any missing type/url/data properties, by picking up the values from a form (or form elements) automatically.
Like so:
http://jsfiddle.net/mindplay/ZDvvm/3/
This takes considerably less code, and it's more open-ended and general purpose, since all it does it provide defaults.
For that matter, you can -1 the $.post() and $.get() functions for all I care - they're not useful, they're a tease ;-)
Changed June 08, 2011 01:32AM UTC by comment:5
Sorry, make that:
Thanks for your time and interest in helping out the jQuery project. The jQuery Form Plugin has handled this for quite some time, and my general sense is that we're happier leaving functionality like this outside of core and in the plugin of the user's choice. One complication, of course, is that this doesn't even handle forms that have file inputs. The other assumption that "basically every" jQuery application does this is certainly overstated - there are any number of common UX and other patterns that occur with regularity throughout the jQuery-verse whose inclusion is not merited in core. I've built sites where I needed the form plugin, and sites where I didn't. Since "getting this right" is obviously not as simple as posted here, I think we're going to punt on this, but I'll leave it open for other folks to leave their opinion before closing, but I'm firmly -1 on this one. Sorry to rain on your parade!