开发者

Is it appropriate to dispense with <form> tags when building an ajax application?

I'm working on an ajax application that makes extensive use of jQu开发者_如何学Cery. I'm not worried about whether or not the application degrades gracefully.

So far I have been using Malsup's excellent jQuery form plugin to create forms that submit ajax requests. (For example, to submit updated record information.)

However I am considering dispensing with form tags altogether, and instead manually constructing $.post() statements when needed.

I'm wondering: What are peoples' thoughts on the best way to submit a large amount of information to the server - considering graceful degradation is not a requirement. Are there perils with just using $.post()?

Thanks in advance


Nope, not at all. That's all the plugin is doing anyway, under the hood.

The form tag does at least provide you with a nice structural grouping of your form tags, so that you can query for them more easily, though.


You've said it yourself - the peril is that it won't degrade gracefull!

Have jQuery add an extra field called UsingjQuery, then output your results based on whether this field is set or not.

This way users with javascript turned off (mobile clients, etc) will still be able to submit.

edit: Saw you mentioned 'degrades gracefully' but somehow didn't see it said 'not worried about' first!

Having a form tag does allow one javascript trick that jQuery doesn't support without: $('form').reset() ...


I stopped using FORM tags some time ago, but I also have a set of captured users that I know exactly what platform they are using.


I agree with David Pfeffer, however, I would also make the point that on occasion, form tags can get in your way. I've specifically had problems where I wanted multiple forms inside of a table, but that caused really ugly problems with positioning. So, I wound up dropping just the input elements in, copying them into a form that was elsewhere on the page, then submitting that form. It was a bit of a pain in the butt.

If you can do away with forms, and aren't worried about degradation, then I would highly consider it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜