本文介绍了AJAX会话Cookie在OS X Dashboard上的Widget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Dashboard小工具的OS X的使用AJAX我用远程API进行交互。我使用jQuery来缓解Ajax实现。我有工作的API需要登录,并使用正常的会话cookie。我在成功登录,但做了后续的AJAX调用失败,因为没有登录。看来,小部件/ jQuery的/ Ajax不是存储/使用会话cookie。我在想什么?

 功能登录(E,P){
    $阿贾克斯({
        网址:网址+sessions.json
        键入:POST,
        数据: {
            登录:E,
            密码:P
        },
        成功:函数(RES){
            getProjects();
        },
        数据类型:JSON,
        xhrFields:{
            withCredentials:真
        }
    });
}

功能getProjects(){
    $阿贾克斯({
        网址:网址+projects.json
        键入:GET,
        数据: {
        },
        成功:函数(RES){

            执行console.log(RES);
        },
        数据类型:JSON,
        xhrFields:{
            withCredentials:真
        }
    });
}
 

解决方案

我碰到的解决了这个问题,同时研究别的东西。

Phonegap应用程序使用身份验证的Rails 3应用程序通信

I am developing a Dashboard widget for OS X. Using AJAX I am interacting with a remote API. I am using jQuery to ease the ajax implementation. The API I am working with requires a login and uses normal session cookies. I am successfully logging in but doing a subsequent AJAX call fails due to not being logged in. It appears that the widget/jQuery/ajax is not storing/using the session cookie. What am I missing?

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
        }
    });
}
解决方案

I came across the solution to this problem while researching something else.

Phonegap App communicate with Rails 3 App using authentication

这篇关于AJAX会话Cookie在OS X Dashboard上的Widget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 22:08