如何使用Ajax和PHP进行会话控制
我必须在web服务中使用javascript登录(mede with cake php),如果我使用common request(非ajax),一切都很好,但是当我在countUpdates上登录后使用下面的代码时,我得到了403。在登录countUpdates之后,ajax调用发送了一个不同于其他调用的cake会话cookie,这是对的还是在ajax上使用了一个技巧 这是我的JavaScript代码:如何使用Ajax和PHP进行会话控制,php,jquery,ajax,session,Php,Jquery,Ajax,Session,我必须在web服务中使用javascript登录(mede with cake php),如果我使用common request(非ajax),一切都很好,但是当我在countUpdates上登录后使用下面的代码时,我得到了403。在登录countUpdates之后,ajax调用发送了一个不同于其他调用的cake会话cookie,这是对的还是在ajax上使用了一个技巧 这是我的JavaScript代码: function Api() { } Api.login
function Api() {
}
Api.login = function(callback)
{
$.post("api/login/{0}?no-cache={1}".format(Api.udid, Math.random()), null, function(response) {
callback(response);
}, 'json');
};
Api.logout = function(callback)
{
$.post("api/logout/?no-cache={0}".format(Math.random()), null, function(response) {
callback(response);
}, 'json');
};
Api.countUpdates = function(last_update, callback)
{
$.post("api/countUpdates/{0}?no-cache={1}".format(last_update, Math.random()), null, function(response) {
callback(response);
}, 'json');
};
$(document).ready(function() {
Api.udid = "2b6f0cc904d137be2e1730235f5664094b831186";
Api.logout(function(response)
{
console.log(response);
});
Api.login(function(response)
{
if (response.result)
{
Api.countUpdates(0, function(response) {
console.log(response);
});
}
});
});
我很抱歉这是我的错: 解决方案:
Api.logout(function(response)
{
Api.login(function(response)
{
if (response.result)
{
Api.countUpdates(0, function(response) {
console.log(response);
});
}
});
});