[英]Setting a custom header on the server-side, and retrieve its value using JavaScript on the client side
Is it possible to set a custom header as part of a GET response from the server-side, and retrieve its value using JavaScript/JQuery on the client side once the response is received? 是否可以在服务器端将自定义标头设置为GET响应的一部分,并在收到响应后在客户端使用JavaScript / JQuery检索其值?
If so, what is the proper way of doing this in JavaScript? 如果是这样,用JavaScript执行此操作的正确方法是什么?
As mentioned in the comments to your question, the answer is no, not directly. 如您对问题的评论中所述,答案是否定的,不是直接的。
If you really need to do this, as a workaround you can push values as hidden fields if returning HTML, part of your response if returning JSON etc. 如果您确实需要执行此操作,作为一种解决方法,如果返回HTML,则可以将值作为隐藏字段推入,如果返回JSON,则可以将响应作为推入的一部分。
If you absolutely, unavoidably need to do this, you can make a separate HEAD XMLHTTPRequest to the desired page, and load the headers from there. 如果绝对(不可避免地)需要执行此操作,则可以对所需的页面创建一个单独的HEAD XMLHTTPRequest,然后从此处加载标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.