admin管理员组

文章数量:1389903

I've been developing a "Form Builder" in Javascript, and ing up to the part where I'll be sending the spec for the form back to the server to be stored. The builder maintains an internal data structure that represents the fields, label, options (for select/checkbox/radio), mandatory status, and the general sorting order of the fields.

When I want to send this structure back to the server, which format should I municate it with?

Also, when restoring a server-saved form back into my Javascript builder, should I load in the data in the same format it sent it with, or should I rebuild the fields using the builder's createField() functions?

I've been developing a "Form Builder" in Javascript, and ing up to the part where I'll be sending the spec for the form back to the server to be stored. The builder maintains an internal data structure that represents the fields, label, options (for select/checkbox/radio), mandatory status, and the general sorting order of the fields.

When I want to send this structure back to the server, which format should I municate it with?

Also, when restoring a server-saved form back into my Javascript builder, should I load in the data in the same format it sent it with, or should I rebuild the fields using the builder's createField() functions?

Share Improve this question edited Oct 14, 2015 at 12:53 Sarjan Desai 3,7332 gold badges20 silver badges32 bronze badges asked Aug 19, 2008 at 16:49 mercutiomercutio 22.6k10 gold badges37 silver badges37 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 5

When making and processing requests with JavaScript, I live and breath JSON. It's easy to build on the client side and there are tons of parsers for the server side, so both ends get to use their native tongue as much as possible.

This seems like a perfect scenario for using JSON as a serialization format for the server. If you study a few examples it is not too difficult to understand.

Best practice on this dictates that if you are not planning to use the stored data for anything other than recreating the form then the best method is to send it back in some sort of native format (As mentioned above) With this then you can just load the data back in and requires the least processing of any method.

I'd implement some sort of custom text serialization and transmit plain text. As you say, you can rebuild the information doing the reversed process.

There's a lot of people who will push JSON. It's a lot lighter weight than XML. Personally, I find XML to be a little more standard though. You'll have trouble finding a server side technology that doesn't support XML. And JavaScript supports it just fine also.
You could also go a pletely different route. Since you'll only be sending information back when the form design is plete, you could do it with a form submit, for a bunch of hidden fields. Create your hidden fields using JavaScript and set the values as needed.
This would probably be the best solution if didn't want to deal with JSON/XML at all.

本文标签: Communication between Javascript and the serverStack Overflow