为什么要使用JSON而不是AJAX的普通html输出? [英] Why use JSON instead a normal html output with AJAX?

查看:103
本文介绍了为什么要使用JSON而不是AJAX的普通html输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么最好在调用ajax中使用输出json而不是普通的html输出? 是使用它的原因还是在更特殊的情况下使用它呢?

Why is better use an output json instead the normal html output in a call ajax? Wich are the reason for use it or in wich scenario is more useful use it?

推荐答案

JSON很容易被JavaScript解析,而且重量轻.

JSON is easily parsed by JavaScript and it is lightweigh.

返回JSON是通用化.即,除了您的浏览器之外,其他任何可以处理JSON的客户端都可以利用服务器的响应.在这种情况下,您的数据和表示位于单独的层中.

Returning as JSON is generalization. i.e apart from your browser any other client which can process JSON can make use of response from the server. In this case your data and presentation are in separate layers.

作为HTML返回是专业化的.并非所有客户端都可以处理HTML响应.在这种情况下,您要将数据和表示层绑定在一起.

Returning as HTML is specialization. Not all client can process the HTML response. In this case you are binding the data and presentation layer together.

还有另一个线程对此进行了详细讨论. 为什么每个人都为jQuery选择XML之上的JSON?

There is a another thread that have discussed about this in details. Why is Everyone Choosing JSON Over XML for jQuery?

这篇关于为什么要使用JSON而不是AJAX的普通html输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆