關於http狀態代碼204理解

來源:互聯網
上載者:User

標籤:

HTTP的狀態代碼有很多種,主要有1xx(臨時響應)、2xx(成功)、3xx(已重新導向)、4xx(請求錯誤)以及5xx(伺服器錯誤)五個大類,每個大類還對應一些具體的分類。平時我們接觸比較多的是200、400、500等。

這裡我們主要討論一下狀態代碼204,在HTTP RFC 2616中關於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.

意思等同於請求執行成功,但是沒有資料,瀏覽器不用重新整理頁面.也不用導向新的頁面。如何理解這段話呢。還是通過例子來說明吧,假設頁面上有個form,提交的url為http-204.htm,提交form,正常情況下,頁面會跳轉到http-204.htm,但是如果http-204.htm的相應的狀態代碼是204,此時頁面就不會發生轉跳,還是停留在當前頁面。另外對於a標籤,如果連結的頁面響應碼為204,頁面也不會發生跳轉。

所以對於一些提交到伺服器處理的資料,只需要返回是否成功的情況下,可以考慮使用狀態代碼204來作為返回資訊,從而省掉多餘的資料轉送。

關於http狀態代碼204理解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.