Netflix如何在没有页面刷新的情况下提交评分,而且没有JavaScript? [英] How does Netflix submit ratings without a page refresh, and no JavaScript?
问题描述
以下是Netflix上的链接示例:
< a href =http://movies.netflix.com/SetRating?value=5&pval=4.8&widgetid=M70186045_496624_2_36&authURL=1272123378738.TS7qzDVHSE6abcEeRPuqldimKYc%3C& section = QUEUEclass =rv5tabindex =0title ='点击评分电影Loved It'>评分5星< / a>
有人知道Netflix是如何做到这一点的?
提示:如果您查看源代码并执行搜索,则不会在任何地方找到iframe。
另外,它在JavaScript关闭时表现出这种行为。否则它会更新数据并且不需要手动刷新。所以也没有AJAX。自己检查一下,我相信你们很多人都有Netflix账户。
header(HTTP / 1.0 204无回应);
如此处所述: http://php.net/manual/en/function.header.php#32569
如果你没有使用过,HTTP Response 204可以非常方便。 204会通知服务器立即终止该请求。如果您希望使用JavaScript(或类似的)客户端功能执行服务器端功能而不刷新或更改当前网页,这会很有帮助。非常适合更新数据库,设置全局变量等。
这是我现在在脚本中使用的。
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.
这篇关于Netflix如何在没有页面刷新的情况下提交评分,而且没有JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!