普通表单提交与JSON [英] Normal form submission vs. JSON

查看:103
本文介绍了普通表单提交与JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了在客户端获得JSON响应和格式设置的优势,但是与普通提交相比,使用JSON进行表单提交有什么优势吗?

I see advantages of getting JSON response and formatting in client side but are there any advantages by using JSON for form submission compared to normal submission?

推荐答案

处理POST数据时想到的一件事是无用的重复:

One thing comes to mind when dealing with POST data is useless repetition:

例如,在POST中,我们有以下内容:

For example, in POST we have this:

partners[]=Apple&partners[]=Microsoft&partners[]=Activision

我们实际上可以看到,这里有很多重复,就像我们发送JSON时一样:

We can actually see, that there is a lot of repetition here, where as when we are sending JSON:

{"partners":["Apple","Microsoft","Activision"]}

59个字符对47个字符.在这个小样本中,它看起来微不足道,但是这些节省可能会不断增加,甚至几个字节也可以为您节省一些数据.当然,在服务器端可以进行数据解析,甚至可以消除差异,但是,在处理较慢的连接(查看您,3G和EDGE)时,我仍然看到有时这会有所帮助.

59 characters versus 47. In this small sample it looks miniscule, but these savings could go up and up, and even several bytes will save you some data. Of course, there is the parsing of data on server side, which could even out the differences, but still, i saw this sometimes helping when dealing with slower connections (looking at you, 3G and EDGE).

这篇关于普通表单提交与JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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