add Ox.Cookie, send X-CSRFToken if csrftoken cookie is set
This commit is contained in:
parent
0ba564c104
commit
852641335d
2 changed files with 26 additions and 0 deletions
20
source/Ox.UI/js/Core/Cookies.js
Normal file
20
source/Ox.UI/js/Core/Cookies.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
Ox.Cookies = function() {
|
||||
var name, value, cookies;
|
||||
if (arguments.length == 1) {
|
||||
name = arguments[0];
|
||||
return Ox.Cookies()[name];
|
||||
} else if (arguments.length == 2) {
|
||||
name = arguments[0];
|
||||
value = arguments[1];
|
||||
document.cookie = name + '=' + encodeURIComponent(value);
|
||||
} else {
|
||||
value = {}
|
||||
if (document.cookie && document.cookie != '') {
|
||||
document.cookie.split('; ').forEach(function(cookie) {
|
||||
name = cookie.split('=')[0];
|
||||
value[name] = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -136,6 +136,12 @@ Ox.Request = (function() {
|
|||
} else {
|
||||
pending[options.id] = true;
|
||||
$.ajax({
|
||||
beforeSend: function (request) {
|
||||
var csrftoken = Ox.Cookies('csrftoken');
|
||||
if (csrftoken) {
|
||||
request.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
}
|
||||
},
|
||||
complete: complete,
|
||||
data: options.data,
|
||||
//dataType: 'json',
|
||||
|
|
Loading…
Reference in a new issue