http状态码204理解
生活随笔
收集整理的這篇文章主要介紹了
http状态码204理解
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
HTTP的狀態(tài)碼有很多種,主要有1xx(臨時(shí)響應(yīng))、2xx(成功)、3xx(已重定向)、4xx(請(qǐng)求錯(cuò)誤)以及5xx(服務(wù)器錯(cuò)誤)五個(gè)大類,每個(gè)大類還對(duì)應(yīng)一些具體的分類。平時(shí)我們接觸比較多的是200、400、500等。
這里我們主要討論一下狀態(tài)碼204,在HTTP RFC 2616中關(guān)于204的描述如下:
If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent’s active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent’s active view.
意思等同于請(qǐng)求執(zhí)行成功,但是沒(méi)有數(shù)據(jù),瀏覽器不用刷新頁(yè)面.也不用導(dǎo)向新的頁(yè)面。如何理解這段話呢。還是通過(guò)例子來(lái)說(shuō)明吧,假設(shè)頁(yè)面上有個(gè)form,提交的url為http-204.htm,提交form,正常情況下,頁(yè)面會(huì)跳轉(zhuǎn)到http-204.htm,但是如果http-204.htm的相應(yīng)的狀態(tài)碼是204,此時(shí)頁(yè)面就不會(huì)發(fā)生轉(zhuǎn)跳,還是停留在當(dāng)前頁(yè)面。另外對(duì)于a標(biāo)簽,如果鏈接的頁(yè)面響應(yīng)碼為204,頁(yè)面也不會(huì)發(fā)生跳轉(zhuǎn)。
所以對(duì)于一些提交到服務(wù)器處理的數(shù)據(jù),只需要返回是否成功的情況下,可以考慮使用狀態(tài)碼204來(lái)作為返回信息,從而省掉多余的數(shù)據(jù)傳輸。
這里我們主要討論一下狀態(tài)碼204,在HTTP RFC 2616中關(guān)于204的描述如下:
If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent’s active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent’s active view.
意思等同于請(qǐng)求執(zhí)行成功,但是沒(méi)有數(shù)據(jù),瀏覽器不用刷新頁(yè)面.也不用導(dǎo)向新的頁(yè)面。如何理解這段話呢。還是通過(guò)例子來(lái)說(shuō)明吧,假設(shè)頁(yè)面上有個(gè)form,提交的url為http-204.htm,提交form,正常情況下,頁(yè)面會(huì)跳轉(zhuǎn)到http-204.htm,但是如果http-204.htm的相應(yīng)的狀態(tài)碼是204,此時(shí)頁(yè)面就不會(huì)發(fā)生轉(zhuǎn)跳,還是停留在當(dāng)前頁(yè)面。另外對(duì)于a標(biāo)簽,如果鏈接的頁(yè)面響應(yīng)碼為204,頁(yè)面也不會(huì)發(fā)生跳轉(zhuǎn)。
所以對(duì)于一些提交到服務(wù)器處理的數(shù)據(jù),只需要返回是否成功的情況下,可以考慮使用狀態(tài)碼204來(lái)作為返回信息,從而省掉多余的數(shù)據(jù)傳輸。
總結(jié)
以上是生活随笔為你收集整理的http状态码204理解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: AAP HID
- 下一篇: dir-616 c1语言包,D-Link