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?
5 Answers
Reset to default 5When 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
版权声明:本文标题:Communication between Javascript and the server - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744654296a2617871.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论