0

I am writing java servlet using tomcat as servlet container.

I need a client to create an ajax-request and get json object as response.

After that client construct a HTMLElement from this json object (parsing it to js object first).

The question: is there a way to have a complete element right after parsing a json without manually setting attribute to attribute (like, HTMLElement.Property = Parsed_Json.Property)?

Because if I need to set all this manually, then I need to know what type of element I get (and use one field in JSON as tagName). But this will require something like

var button = document.createElement(Parsed_Json.ElementTag);

And then a big "if" block to realize which properties I need to set.

Maybe I can replicate the structure of a complete object in json so it will be usable right after

var HTMLElement = Json.parse(json_object); 

and I will be able to do just a

body.appendChild(HTMLElement);
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.