I'm trying to retrieve an HTML via JSON and i don't know if i'm implementing the best practice for that...
Here's an example:
jsonRequest = [
{
"id": "123",
"template": '<div class=\"container\">Hello, guys, i am a json</div>'
}];
There's some other way to use it?
Not sure if there is really a "best practice" in that case. This depends on multiple factors.
First JSON is just a notation, so as long as you provide a valid String content for the template property it is valid (and best practice)
Second I would treat it differently based on the template size. If it is only such a small html template, I think wrapping it inside a JSON can make sense in some cases.
However if you try to render an entire page with the template, I'd suggest to only provide a link to the template in the property and then fetch the template with this link. This keeps your JSON clean and readable (and a lot easier to debug)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.