是否可以读取请求标头,然后在jquery mobile + javascript代码中获取变量值(例如用户ID)?如果是的话有什么例子
我找到了这篇文章。 How to get read data from response header in jquery/javascript,但不确定它是如何运作的。
答案 0 :(得分:3)
答案 1 :(得分:1)
$.ajax({
type: 'POST',
url:'url', //the request url
data: {}, //any param that you want to send in the request
success: function(data){ //'data' is the response
alert(request.getResponseHeader());
}
error: function () {
alert("failed");
}
});
答案 2 :(得分:0)
如果你想要这个页面的请求标题,你可以通过php getallheaders获取它们并将它们显示为javascript数组。
<script>
var headers = <?php echo json_encode(getallheaders()); ?>;
</script>