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

前端 未结 1 878
鱼传尺愫
鱼传尺愫 2021-02-04 21:36

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

相关标签:
1条回答
  • 2021-02-04 22:11

    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.

    0 讨论(0)
提交回复
热议问题