Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有一个页面,其中包含我网站的 json 格式用户列表。我正在使用 jquery getJson 从该 url 获取 dat,但如果用户试图通过 http 请求打开它,我需要这些页面不可访问。
request.xhr?您可以使用检查header[X-Requested-With]请求的值来过滤特定操作。
request.xhr?
header[X-Requested-With]
def your_action unless request.xhr? render status: 404 # or what you want return end # action code end