EZ ITT A REKLÁM HELYE

lenI

Netes megaszondás - Digital Craftmanship WEB, mobil, development, on-line media, VOD, social, Android, ios, mac... God bless the content! Disclaimer: lenI az Inda-labs és index.hu főmunkatársa volt. Jelenleg Cloud ügyi Agilis PO az EU-ban

Anno: 2010.01.24
HDA success: 2010.02.15

lenI on google
Coelhos

NAPSZÁM

Magyarorszag napja az Európai Unió tagja.
A régi radiocafé 98.6 napja hallgat. R.I.P.
De 2022.12.01-el megint van barátod: 98.0-on!

Any has gone napja, és szivárványt fest nekünk.

Zsozso pedig már napja mosolyogtat.

Krisi meg napja meg nem áll napközben.

Dédi has gone napja, és fentről szórja áldásait ránk.

Címkék

2009 (3) 2010 (47) 2011 (25) 2012 (16) 2013 (4) 2014 (6) ad (12) adobe (3) amazon (3) android (6) api (3) app (9) apple (12) blog (13) blog.hu (29) bloghu (23) browser (5) bug (8) business (3) cemp (5) chrome (5) cool (6) data (3) ddos (3) design (11) desire (3) dev (27) development (3) display (3) email (3) facebook (46) facepalm (8) fail (3) fejlesztés (4) fidesz (3) film (7) fix (3) flash (4) forum (4) gemius (4) gmail (6) google (42) gui (4) hackintosh (3) hirdetés (8) htc (4) hu (31) hvg (4) inda (50) indafoto (7) indamail (6) indanet (4) indavideo (14) index (49) index.hu (18) indexvideo (3) infographics (5) internet (84) internetadó (3) ios (5) ipad (6) iphone (7) it (38) IT (3) iwiw (10) jog (4) js (3) leni (9) like (6) linkedin (3) lol (10) london (3) lumia (4) mac (6) magyar (4) magyarország (5) mail (8) maps (4) market (3) marketing (4) media (12) memento (18) microsoft (10) mobil (30) mobile (3) mood (3) myspace (6) netflix (3) news (15) nokia (9) olimpia (3) online (8) origo (21) osx (8) phone (3) php (5) pinterest (3) player (3) politika (4) redesign (3) security (3) share (8) social (14) sweb (29) tech (10) trend (3) tumblr (6) twitter (14) up (5) update (6) usa (3) ux (8) vb2010 (5) videó (3) video (30) viral (3) vod (3) web (44) webdesign (3) windows (3) wow (3) yahoo (8) youtube (12) zizz (4) Címkefelhő

2012.09.24. 22:47 Leni

HTTP 204 - idéznék

Címkék: dev php development w3c http weblabor 204 optimization programing web server statuscodes

Az alábbi post Brian Mark 2007-ben publikálta, és most azt gondolom, érdekes lehet.

HTTP 204 - the forgotten status

With everyone being so hot to use Ajax for things now, it seems that people forget how much simpler things can be done if you just stop and use some old-school techniques. I know I like Ajax for some things, but if it isn't necessary, then why introduce the extra bit of complexity?

I'm speaking here about the 204 status code.

Quoting the W3

204 No Content

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

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.

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.


For doing simple updates, a 204 works beautifully. Pass some parameters, save some values, but leave the user right where they are. This is great for online forms where you want to save values as they get typed / changed but don't need to return anything back to the user.

One quick warning, though. PHP is notorious for not presenting proper 204's, so if you code in PHP, you'll want to hand code the entire response.

Now that you understand what it is, why would it get used?

Let's say for a minute, that you have a form that has 30 - 40 checkboxes (like for a permissions based admin section of a site) and want to turn them on and off. You don't really need to give any feedback that the permission has been added / removed, you just need to save the value.

Well, the easy answer (if you ask me) is to use a bit of javascript to request a location (document.location=_____) with some parameters for this.value and the username. When it gets requested, if it works a 204 can be returned, if not a page with an error message can be shown instead.

Or let's say you've got a whole list of options set up via radio buttons and want to enable people to answer a survey and come back later to finish. As each option gets changed, a quick request with a 204 return code could save the answer, then the response is saved for when they come back.

I haven't seen too many places utilize this type of a system, but we use it quite a bit. The real benefits are less overload on the client side, but also once the request is made, you don't have to wait for a response before the next request is made. Ajax can be slow processing a bunch of requests at times (they normally run sequentially, not in parallel), but by not using Ajax and calling a script that returns a 204, they can all be running at once if needed.

There are other status codes that don't get used too often. The full list can be foundhere.

Szólj hozzá!

EZ ITT A REKLÁM HELYE

A bejegyzés trackback címe:

https://leni.blog.hu/api/trackback/id/tr954800799

Kommentek:

A hozzászólások a vonatkozó jogszabályok  értelmében felhasználói tartalomnak minősülnek, értük a szolgáltatás technikai  üzemeltetője semmilyen felelősséget nem vállal, azokat nem ellenőrzi. Kifogás esetén forduljon a blog szerkesztőjéhez. Részletek a  Felhasználási feltételekben és az adatvédelmi tájékoztatóban.

Nincsenek hozzászólások.
süti beállítások módosítása