Fix sending feedbacks

This commit is contained in:
printempw 2018-08-16 17:05:15 +08:00
parent 79bcff0d26
commit 4e37fbd2b5
2 changed files with 12 additions and 0 deletions

View File

@ -1338,6 +1338,7 @@ describe('tests for "common" module', () => {
url: 'https://work.prinzeugen.net/statistics/feedback',
type: 'POST',
dataType: 'json',
xhr: expect.any(Function),
data: { site_name: 'inm', site_url: 'http://tdkr.mur', version: '8.1.0' }
});
expect(window.document.cookie).not.toBe('');

View File

@ -31,6 +31,17 @@ async function sendFeedback() {
site_name: blessing.site_name,
site_url: blessing.base_url,
version: blessing.version
},
xhr: () => {
// Don't send 'X-CSRF-TOKEN' header to a cross-origin server
// @see https://gist.github.com/7kfpun/a8d1326db44aa7857660
const xhr = $.ajaxSettings.xhr();
const setRequestHeader = xhr.setRequestHeader;
xhr.setRequestHeader = function (name, value) {
if (name === 'X-CSRF-TOKEN') return;
setRequestHeader.call(this, name, value);
};
return xhr;
}
});
if (errno === 0) {