Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Netflix submit ratings without a page refresh, and no JavaScript?

Tags:

html

http

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&section=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.

like image 350
Adam11 Avatar asked Jan 13 '23 00:01

Adam11


1 Answers

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.

like image 118
Adam11 Avatar answered Jan 30 '23 23:01

Adam11