本文介绍了Netflix如何在没有页面刷新的情况下提交评分,而且没有JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的网站做Netflix的五星评级系统,我注意到Netflix即使禁用了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账户。

经过多一点研究后,我发现我正在寻找的答案。您可以通过从您发送请求的页面发送HTTP响应204状态代码来完成此操作。例如,假设你将它发送到一个php脚本,用这个开始页面:

  header(HTTP / 1.0 204无回应); 

如此处所述:

这是我现在在脚本中使用的。


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.

解决方案

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

This is what I'm now using in my scripts.

这篇关于Netflix如何在没有页面刷新的情况下提交评分,而且没有JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 15:48