I'm trying to do something like Netflix's 5 star rating system for my website, and I've noticed that Netflix, even with JavaScript disabled, will still submit ratings without a page refresh. This is apparent because when you manually reload the page, you can see the new rating. However, the change is not visible until you reload the page.
Here's an example of a link on Netflix:
<a href="http://movies.netflix.com/SetRating?value=5&pval=4.8&widgetid=M70186045_496624_2_36&authURL=1272123378738.TS7qzDVHSE6abcEeRPuqldimKYc%3C§ion=QUEUE" class="rv5" tabindex="0" title='Click to rate the movie "Loved It"'>Rate 5 stars</a>
Anybody know how Netflix does this?
Hint: if you look at the source and do a search, you will not find 'iframe' anywhere. Also, it exhibits this behavior with JavaScript OFF. Otherwise it would update the data and not require a manual refresh. So no AJAX, either. Check it out for yourself, I'm sure many of you have Netflix accounts.
After a little more research, I found the answer I was looking for. You can do this by sending an HTTP response 204 status code from the page you are sending your request to. For instance, assuming you're sending it to a php script, start the page with this:
header("HTTP/1.0 204 No Response");
As stated here: http://php.net/manual/en/function.header.php#32569
If you haven't used, HTTP Response 204 can be very convenient. 204 tells the server to immediately terminate this request. This is helpful if you want a javascript (or similar) client-side function to execute a server-side function without refreshing or changing the current webpage. Great for updating database, setting global variables, etc.
This is what I'm now using in my scripts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With