使用JQuery或其他类似框架从自定义url /Web服务加载HTML内容非常容易。到目前为止,我已经多次使用这种方法,并发现性能令人满意。
但是所有的书,所有的专家都试图让我使用JSON而不是生成的HTML。它为什么比HTML更优越?
它会快很多吗?
它在服务器上的负载是否非常小?
另一方面,我有一些使用生成HTML的理由。
它是简单的标记,通常和JSON一样紧凑,甚至更紧凑。
它更不容易出错,因为你得到的都是标记,而不是代码。
在大多数情况下,编程会更快,因为你不必为客户端单独编写代码。
你站在哪一边,为什么?
IMV, it's all about separating the data from the presentation of the data, but I'm with Pascal, it doesn't necessarily follow that that separation can only be across the client/server boundary. If you have that separation already (on the server) and just want to show something to the client, whether you send back JSON and post-process it on the client, or just send back HTML, depends entirely on your needs. To say you're "wrong" to send back HTML in the general case is just far too blanket a statement IMV.
IMV, it's all about separating the data from the presentation of the data, but I'm with Pascal, it doesn't necessarily follow that that separation can only be across the client/server boundary. If you have that separation already (on the server) and just want to show something to the client, whether you send back JSON and post-process it on the client, or just send back HTML, depends entirely on your needs. To say you're "wrong" to send back HTML in the general case is just far too blanket a statement IMV.