【发布时间】:2012-04-13 23:05:09
【问题描述】:
正如标题所暗示的那样:
我向我的服务器执行一个 ajax 请求,它以 403 响应,但我想检索一些标头并将其保存在 localStorage 上。这适用于 phonegap 应用程序(Android 和 iOS),因此启动域是本地 (file://)。在执行调用时,我使用以下代码尝试拦截响应,但它返回 undefined 或空字符串。
阿贾克斯:
$.ajax({
url: serverLink+action,
type: "POST",
data: "access_token="+accessToken+"&uid="+uid,
crossDomain: true,
complete: function(resp){
var header = resp.getAllResponseHeaders();
var match = header.match(/(Set-Cookie|set-cookie): (.+?);/);
if (match) session = match[2];
console.log(header, session)
}
})
响应标头
Connection Keep-Alive
Content-Encoding gzip
Content-Length 1198
Content-Type text/html
Date Fri, 13 Apr 2012 22:51:02 GMT
Keep-Alive timeout=15, max=100
Server Apache/2.2.14 (Ubuntu)
Set-Cookie sessionid=ebd26167e32bada2d2ed0bd3cc16d8a2; expires=Fri, 27-Apr-2012 22:51:02 GMT; Max-Age=1209600; Path=/
Vary Cookie,Accept-Encoding
进一步阅读将我带到here,它谈到了 django 服务器上的 CSRF。我们正在使用 django 服务器,我怀疑这个或 403 是问题所在。似乎没有办法(从那里的示例答案)从 webview 收集 cookie 并在后续请求中将其发送回服务器。
【问题讨论】:
标签: javascript jquery ajax header response