我想使用angular发布带有CSRF令牌的表单。我在Jquery中有一个工作代码,但无法弄清楚如何将它转换为Angular。
$("body").on("click", "#logout", function() {
var url = "http://localhost/lab/theapp/api/user/logout.json";
try {
$.ajax({
url: url,
type: 'post',
dataType: 'json',
beforeSend: function (request) {
request.setRequestHeader("X-CSRF-Token", $.cookie('token'));
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('button_logout - failed to logout');
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
alert("You have been logged out.");
}
});
}
catch (error) { alert("button_logout - " + error); }
return false;
});
另外如何使用angular访问/设置cookie?