简体   繁体   English

如何在浏览器中存储服务器HTTP响应标头?

[英]How to store server HTTP response header in browser?

In my PHP application, I get a page by Ajax request and load it into a specific div element of the page. 在我的PHP应用程序中,我通过Ajax请求获取页面并将其加载到页面的特定div元素中。 I am sending some headers from server in response too. 我也从服务器发送一些标头作为响应。

How to store that headers in browser? 如何在浏览器中存储标题?

actually as i had mentioned above , through ajax i am loading page and browser url remains unchanged during process , and when i am clicking back button of browser it is redirecting me to very first page of application. 实际上,正如我上面提到的,通过ajax,我正在加载页面,并且浏览器的URL在处理过程中保持不变,并且当我单击浏览器的后退按钮时,它会将我重定向到应用程序的第一页。 all i am trying to do is to store name of requested page by ajax in that browser history which helps back button to navigate functionality . 我要做的就是在浏览器历史记录中存储ajax请求页面的名称,这有助于后退按钮导航功能。

what i am thinking is possible logically? 在逻辑上我在想什么呢?

The success function called by your jQuery $.ajax request will have a jqXHR object as its third argument. jQuery $.ajax请求调用的success函数将有一个jqXHR对象作为其第三个参数。 You can use this object's getResponseHeader() method to get the response headers from the server's http response. 您可以使用该对象的getResponseHeader()方法从服务器的http响应中获取响应头。 See the docs for more info: http://api.jquery.com/jQuery.ajax/#jqXHR 有关更多信息,请参阅文档: http : //api.jquery.com/jQuery.ajax/#jqXHR

For example: 例如:

$.ajax({
    url: "...",
    success: function(data, responseText, jqXHR) {
        var headers = jqXHR.getResponseHeader();
        // Do what you will with the headers here
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM