I am starting to do JS / HTML / CSS. Looking back, it seems that it is non-standard to return HTML from an external one (for example, an Ajax response) and directly display it (for example, assigning it to an innerHTML element). For example, I believe that the jQuery load () method is basically a shortcut to this.
Taking the approach bothers me for several reasons, but I'm not sure that I'm just not familiar with the approaches and idioms in these areas, and I'm just lagging behind in time or are these legitimate problems, My problems in particular:
1) It seems unsafe to directly assign HTML to an element. Or, at least, itβs dangerous, at least if there is the possibility of any user-generated content (or even third-party content).
2) Sending presentation information (HTML) directly seems like it could probably lead to a mix of presentations and models that are best avoided. Of course, it would be possible for this data to be completely separate from the background content and still return the HTML, but due to the few projects I saw, this is not the case.
So, to my question: does HTML return a legitimate HTTP response form in an Ajax application or is it better to avoid?
source share