msgbartop
PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 – 左手代码 右手诗
msgbarbottom

20 Jan 11 HTTP 204和205的应用

之前和人讨论过这个问题,,, 今天感冒在家休息, 就回忆了一下, 整理如下.

我们很多的应用在使用Ajax的时候, 大多数情况都是询问型操作, 比如提交数据, 则Ajax只是期待服务器返回:

{status: 0, message:""} //status 0代表成功, 非零的时候, message中包含出错信息.

我们知道HTTP的状态码, 2xx都是表示成功, 而HTTP的204(No Content)响应, 就表示执行成功, 但是没有数据, 浏览器不用刷新页面.也不用导向新的页面.

在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.

类似的还有205 Reset Content, 表示执行成功, 重置页面(Form表单).

The server has fulfilled the request and the user agent SHOULD reset the document view which caused the request to be sent. This response is primarily intended to allow input for actions to take place via user input, followed by a clearing of the form in which the input is given so that the user can easily initiate another input action.

于是, 当有一些服务, 只是返回成功与否的时候, 可以尝试使用HTTP的状态码来作为返回信息, 而省掉多余的数据传输, 比如REST中的DELETE和如上所述的查询式Ajax请求.

最后说说205, 205的意思是在接受了浏览器POST请求以后处理成功以后, 告诉浏览器, 执行成功了, 请清空用户填写的Form表单, 方便用户再次填写,

总的来说, 204适合多次对一个Item进行更新, 而205则适合多次提交一个系列的Item.

但, 请注意, 目前还没有一个浏览器支持205, 大部分的浏览器, 都会把205当做204或者200同样对待.


分享到:



Random Posts:

Tags: , ,

35 Responses to “HTTP 204和205的应用”

  1. Blaine |

    In addition to garage door restore and installations, we are able
    to also do installations and repairs for gates and fences.

  2. Project Supremacy |

    Helpful information. Lucky me I discovered your website by chance,
    and I am surprised why this twist of fate did not happened earlier!
    I bookmarked it.

  3. Raphael |

    If some one wishes to be updated with most up-to-date technologies therefore he must be pay a visit this site
    and be up to date daily.

  4. welcomeMK |

    这个可以试试

  5. free surf |

    Good response in return of this difficulty with solid arguments
    and describing the whole thing about that.

  6. Leo |

    Fantastic website you have here but I was wanting to know if
    you knew of any community forums that cover the same topics talked about
    in this article? I’d really love to be a part of community
    where I can get feedback from other knowledgeable individuals
    that share the same interest. If you have any recommendations, please let me know.
    Thanks a lot!

  7. loretta |

    I’ll immediately grasp your rss as I can’t find your email subscription link or e-newsletter service.
    Do you’ve any? Kindly permit me know in order that I could subscribe.
    Thanks.

  8. Sports98 |

    对于各种浏览器的水土不福。个人觉得这个状态码在专有应用使用还是不错的。如果作为一个公众应用服务可控性太差..

  9. coach |

    One of my favorite methods of keeping focused on a goal is to constantly ask myself, “Is what I’m doing right now bringing me closer to my goal or further away?” Once you answer that question, you’ll know what to do.
    coach http://coachoutletonline.tote2015.com/

  10. bouwtechnische keuring |

    It is in reality a great and helpful piece of info. I’m satisfied
    that you simply shared this useful information with us. Please keep us
    up to date like this. Thank you for sharing.

  11. chaturbate tokens |

    The only things you the truth is need to do is obtain our chaturbate tokens Token Hack, open it and
    also make just a few clicks!

  12. 杰夫 |

    加个 data 放置返回数据就更好了

  13. Jaunita |

    Aw, this was an extremely nice post. Finding the time and actual effort to
    make a superb article… but what can I say… I hesitate a lot and never manage to get nearly
    anything done.

    Feel free to surf to my web site – credit
    sans justificatif a fournir (Jaunita)

  14. free rp codes |

    Fantastic blog you have here butt I was wondering if yyou knew of
    any community orums that cover the same topics
    talked about in this article? I’d really love to be a part of community were I can get feed-back
    from other knowledgeable individuals that share the same interest.
    If you have any recommendations, please let me know.
    Cheers!

  15. Anonymous |

    Actually no matter if someone doesn’t be aware of after that its
    up to other visitors that they will help, so here it occurs.

  16. safestep walk in tub cost |

    I believe what you said was actually very reasonable.
    However, consider this, suppose you were to create a killer post title?
    I mean, I don’t want to tell you how to run your website,
    but suppose you added a headline that grabbed folk’s attention? I mean HTTP 204和205的应用 | 风雪之隅 is kinda plain.
    You ought to look at Yahoo’s home page and see how they create post headlines to grab viewers interested.
    You might try adding a video or a pic or two
    to get people interested about what you’ve written.
    In my opinion, it might bring your posts a little
    bit more interesting.

  17. careerrocketeer.com |

    great put up, very informative. I ponder why the opposite experts of this
    sector don’t realize this. You must continue your writing.

    I’m confident, you’ve a great readers’ base already!

  18. Beyonce Liposuction |

    Hello, i think that i noticed you visited my site so i came to return the favor?.I’m trying
    to to find issues to improve my website!I suppose its adequate
    to use some of your concepts!!

  19. phlebitis treatment |

    Eliminate Dimply skin Thru Natural Massage
    therapies

    There are only a number of women who do not have problems with dimply skin and for that reason there are various “magic supplements” available that aid in reducing your
    bumpy skin. Still each and every girl who has experimented with it has learned that these kinds of anti-cellulite products
    have little or no effect. The most effective way to remove your bumpy
    skin may be the oldest method inside the book!

    Using a targeted anti-cellulite massage therapy, it is possible to successfully remove cellulite from the thighs, legs and bottom.

  20. Alice |

    You should bbe a part of a contest for one oof the most useful blogs on the internet.
    I’m going to recommend this website!

  21. download tool |

    that you are super LUCKY annd (2) total aand complete BELIEF.
    I highly recommend downloading Spybot Search & Destroy, a
    free program, to locate spyware and Lavasoft’s Adaware, also a free program,
    to catch whatever might bbe missed by Spybot. 10meanwhile offers the same image downloading features off the Batch Images Downloader extension ‘ and more.

  22. reklama |

    This blog was… how do you say it? Relevant!! Finally I have found something
    which helped me. Kudos!

  23. Reginald |

    The Phone Broadcast club also uses special software
    to scrub against people that are on the “DNC” or Do Not
    Call List. Whether we’re learning from Robert Kiyosaki, Robert Allen, the folks at Power Prospecting System,
    or our upline mentors, we are always learning and pioneering marketing techniques.
    Many problems are common among multi-level marketers, such as struggling to generate enough leads,
    or make a reasonable amount of sales.

  24. vintage rings |

    Greetings! Very helpful advice iin this particular post!
    It’s the little changes that will make the
    largest changes. Thahks a lot for sharing!}

  25. 怪奇工厂 |

    受益颇丰,谢谢鸟哥

  26. TouchHappy » HTTP 204 And 205 |

    [...] 来源:http://www.laruence.com/2011/01/20/1844.html This entry was written by happy , posted on Tuesday April 12 2011at 08:04 pm , filed under Front-End Development, program . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL. Leave a Reply Click here to cancel reply. [...]

  27. HTTP 204和205的应用 - 简单快乐,享受生活 |

    [...] 来源:http://www.laruence.com/2011/01/20/1844.html [...]

  28. wclssdn |

    不错.. 是不是也可以用其他的码呢? 比如.. 失败了.. 我给他个500- -!! 有空试试~~~

  29. 贝壳里的海 |

    平时接触这两个状态不多,不是很懂

  30. Thinking In LAMP Blog » Blog Archive » PHP每月通讯(2011年2月) |

    [...] http://www.laruence.com/2011/01/20/1844.html HTTP 204和205的应用 [...]

  31. 雪候鸟 |

    @iterse done

  32. iterse's blog |

    比较纠结!
    能帮我加个友链吗,谢谢!

  33. cfc4n |

    用firebug调试ajax的时候,经常返回200,但firebug里看到的却是“加载源码失败”,不知道是不是跟这个有关。

  34. weskerjax |

    400,401 也可以用來處理錯誤狀況
    並可以用 responseText 來傳送錯誤訊息

    對於成功訊息的處理我倒是沒有關注到
    感謝你的文章

  35. xiaobai |

    看到最后一句话,咋这么纠结呢……

Leave a Reply

*