The Artima Developer Community
Sponsored Link

Java Buzz Forum
New webapp trick (http 204 on Amazon)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Steve Conover

Posts: 37
Nickname: sgcjr
Registered: Feb, 2003

Steve Conover is a professional Java engineer and consultant
New webapp trick (http 204 on Amazon) Posted: Jun 26, 2003 10:24 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Steve Conover.
Original Post: New webapp trick (http 204 on Amazon)
Feed Title: Steve Conover's Weblog
Feed URL: http://www.sonic.net/~conover/index.rdf
Feed Description: Mostly java-related.
Latest Java Buzz Posts
Latest Java Buzz Posts by Steve Conover
Latest Posts From Steve Conover's Weblog

Advertisement
New to me at least. Anthony posted about an http 204 trick on Amazon. To see it in action, go the the "Improve your recommendations" section, and then to the page where you rate books. Try giving a book a star rating using the mouseover imagemap - notice that there's a momentary browser submission, and the page now says "Saved" - but the page didn't rebuild. A co-worker and I looked into this a little one day and couldn't figure it out. After reading Anthony's post I went back and looked at the source again...here's the relevant javascript function: function amz_js_sendRating(asin, ratingType, ratingValue) { amz_js_restoreDefaultMessage(asin); var submitURL = '' + '/exec/obidos/instant-recs/102-4930794-1634500?' + 'rating.source=ir' + '&rating.asin.1=' + asin + '&use-new-form=true' + '&return.index.begin=1' + '&rating.' + ratingType + '.1=' + ratingValue + '&not-interested=1' + '&template-name=' + encodeURIComponent( 'stores/recs/ratings/rate-asin-return-page'); if ( ( ( ratingType == 'onetofive' ) || ( ratingType == 'owned' ) ) && ( savedNotInterested[asin] == 1 ) ) { submitURL = submitURL + '&rating.notinterested.1=NONE'; savedNotInterested[asin] = 0; } else if ( ratingType == 'notinterested' ) { if ( savedRatings[asin] > 0 ) { submitURL = submitURL + '&rating.onetofive.1=NONE'; savedRatings[asin] = 0; } if ( savedIsOwned[asin] == 1 ) { submitURL = submitURL + '&rating.owned.1=NONE'; savedIsOwned[asin] = 0; } } window.location.href = submitURL + "&return.response=204"; window.setTimeout( "amz_js_swapThankYouMessage('"+asin+"')", delayTime); } Note that they reset the window href, and send a signal to the server to send an http 204 to the browser. I found the spec entry on http 204: RFC 1945 - Hypertext Transfer Protocol -- HTTP/1.0: 204 No Content The server has fulfilled the request but there is no new information to send back. If the client is a user agent, it should not change its document view from that which caused the request to be generated. This response is primarily intended to allow input for scripts or other actions to take place without causing a change to the user agent's active document view. The response may include new metainformation in the form of entity headers, which should apply to the document currently in the user agent's active view. So in short, you can submit information to the server and not have to do a page rebuild. Which is a nice trick for functionality like in the Amazon example - they have a "Saved" message that they make appear so the user knows something happened....

Read: New webapp trick (http 204 on Amazon)

Topic: Blogs@JavaOne Previous Topic   Next Topic Topic: Project Rave and EJBs

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use