tags:

views:

253

answers:

5

I've been developing a "Form Builder" in Javascript, and coming 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 communicate 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?

A: 

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.

Juan Manuel
+3  A: 

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.

Barrett Conrad
+1  A: 

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. E.g.

David in Dakota
+1  A: 

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.

Jamie Lewis
A: 

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 completely different route. Since you'll only be sending information back when the form design is complete, 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.

Kibbee