1

我正在为 OS X 开发仪表板小部件。使用 AJAX 我正在与远程 API 交互。我正在使用 jQuery 来简化 ajax 实现。我正在使用的 API 需要登录并使用正常的会话 cookie。我已成功登录,但由于未登录,后续的 AJAX 调用失败。看来小部件/jQuery/ajax 没有存储/使用会话 cookie。我错过了什么?

function login(e,p) {
    $.ajax({
        url: url + "sessions.json",
        type: "POST",
        data: {
            login: e,
            password: p
        },
        success: function(res) {
            getProjects();
        },
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        }
    });
}

function getProjects() {
    $.ajax({
        url: url + "projects.json",
        type: "GET",
        data: {
        },
        success: function(res) {

            console.log(res);
        },
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        }
    });
}
4

2 回答 2

0

我在研究其他东西时遇到了这个问题的解决方案。

Phonegap App 使用身份验证与 Rails 3 App 通信

于 2012-08-24T18:40:50.553 回答
0

感谢您分享您的答案:

xhrFields: {
  withCredentials: true
}

然而,对我来说,在 Dashcode 中起作用的是设置 Widget Attributes > Network/Disk Access > Allow External File Access to checked。我一直在寻找某种方法来存储浏览器 cookie,并且通过系统地切换这个和“withCredentials”,最后,似乎 withCreds 对我没有任何帮助,而允许外部文件访问是关键。

希望这可以帮助。

于 2014-01-02T04:26:58.113 回答