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.
我正在尝试为我的网站做Netflix的5星评级系统,我注意到,即使禁用了JavaScript, Netflix仍然会在不刷新页面的情况下提交评级。这很明显,因为当您手动重载页面时,您可以看到新的评级。但是,在重新加载页面之前,更改是不可见的。
Here's an example of a link on Netflix:
以下是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?
有人知道Netflix是怎么做的吗?
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.
提示:如果您查看源代码并进行搜索,您将不会在任何地方找到“iframe”。此外,它还显示了JavaScript关闭后的这种行为。否则,它将更新数据,不需要手动刷新。所以没有AJAX。你自己去看看吧,我相信你们很多人都有Netflix账户。
1 个解决方案
#1
9
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:
经过更多的研究,我找到了我想要的答案。可以通过从发送请求的页面发送HTTP response 204状态码来实现这一点。例如,假设您将它发送到一个php脚本,请以以下方式开始页面:
header("HTTP/1.0 204 No Response");
As stated here: http://php.net/manual/en/function.header.php#32569
这里是这样陈述的: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.
如果您还没有使用,HTTP Response 204可以非常方便。204告诉服务器立即终止此请求。如果您希望javascript(或类似的)客户端函数执行服务器端函数,而不刷新或更改当前的页面,这将非常有用。非常适合更新数据库、设置全局变量等。
This is what I'm now using in my scripts.
这就是我现在在脚本中使用的。
#1
9
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:
经过更多的研究,我找到了我想要的答案。可以通过从发送请求的页面发送HTTP response 204状态码来实现这一点。例如,假设您将它发送到一个php脚本,请以以下方式开始页面:
header("HTTP/1.0 204 No Response");
As stated here: http://php.net/manual/en/function.header.php#32569
这里是这样陈述的: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.
如果您还没有使用,HTTP Response 204可以非常方便。204告诉服务器立即终止此请求。如果您希望javascript(或类似的)客户端函数执行服务器端函数,而不刷新或更改当前的页面,这将非常有用。非常适合更新数据库、设置全局变量等。
This is what I'm now using in my scripts.
这就是我现在在脚本中使用的。