Where correctly to store data in data or json for the calculator service?

0 like 0 dislike
161 views
How to make a calculator calculate the cost of services?
2 questions in one:
1. data - attributes or json?
2. Is it wrong to do input? From the point of view of semantics seems reasonable.

Hidden input with data - attributes + label
image service 1st type

Or create json directly in the js file (not a lot of services, each with 6 parameters), a separate file probably does not make sense.
by | 161 views

3 Answers

0 like 0 dislike
JSON is great because it stored the file on the server, and if necessary, you can edit it, and later, to attach the parameter editor and generate JSON.
Need to get JSON from the server via ajax, and eventually, you will have an object with parameters and prices.
If the parameters a little better instead of attributes, right in the JS file, define a constant object parameters. So when you need more fields, it will be easy to separate the parameters in a separate json file, almost without changing the code.
by
0 like 0 dislike
1. Without a difference, for a small script. And json is better so as less committed type conversion, all stored in one place, less chase DOM.
2. input for such purposes it is desirable to use in fact, will be able to send data to the backend
by
0 like 0 dislike
The JSON format was originally meant to store "objects" and relevant in the task of data exchange between browser and server or between servers. This format is more suitable for the serialization of complex structures.

If the answer to your questions:

1. data - attributes or json?

Data-attributes.

2. Is it wrong to do input? From the point of view of semantics seems reasonable.

Wrong. Input intended for other purposes.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 1, 2019 by GrozInventor
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users