Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions apps/demos/Demos/DataGrid/BatchUpdateRequest/jQuery/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const BASE_PATH = 'http://localhost:5555';
//const BASE_PATH = 'https://js.devexpress.com/Demos/NetCore';
let csrf = null;

$(() => {
const URL = 'https://js.devexpress.com/Demos/NetCore/api/DataGridWebApi';
const URL = `${BASE_PATH}/api/DataGridBatchUpdateWebApi`;

$('#gridContainer').dxDataGrid({
dataSource: DevExpress.data.AspNet.createStore({
Expand All @@ -26,7 +30,8 @@ $(() => {

if (e.changes.length) {
const changes = normalizeChanges(e.changes);
e.promise = sendBatchRequest(`${URL}/Batch`, changes).done(() => {
e.promise = sendBatchRequest(`${URL}/Batch`, changes,
{ [csrf['headerName']]: csrf['token'] }).done(() => {
e.component.refresh(true).done(() => {
e.component.cancelEditData();
});
Expand Down Expand Up @@ -77,12 +82,13 @@ $(() => {
});
}

function sendBatchRequest(url, changes) {
function sendBatchRequest(url, changes, headers) {
const d = $.Deferred();

$.ajax(url, {
method: 'POST',
data: JSON.stringify(changes),
headers: headers,
cache: false,
contentType: 'application/json',
xhrFields: { withCredentials: true },
Expand All @@ -93,3 +99,11 @@ $(() => {
return d.promise();
}
});

(async () => {
const response = await fetch(`${BASE_PATH}/api/Common/GetAntiForgeryToken`, {
credentials: 'include'
});
const data = await response.text();
csrf = JSON.parse(data);
})();
25 changes: 21 additions & 4 deletions apps/demos/Demos/DataGrid/CollaborativeEditing/jQuery/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const BASE_PATH = 'http://localhost:5555';
//const BASE_PATH = 'https://js.devexpress.com/Demos/NetCore';
let csrf = null;

$(() => {
$.type = $.type || function (obj) {
if (obj == null) {
Expand All @@ -7,8 +11,7 @@ $(() => {
return typeof obj;
};

const BASE_PATH = 'https://js.devexpress.com/Demos/NetCore/';
const url = `${BASE_PATH}api/DataGridCollaborativeEditing/`;
const url = `${BASE_PATH}/api/DataGridCollaborativeEditing/`;
const groupId = new DevExpress.data.Guid().toString();

const createStore = function () {
Expand All @@ -20,6 +23,12 @@ $(() => {
deleteUrl: url,
onBeforeSend(method, ajaxOptions) {
ajaxOptions.data.groupId = groupId;
ajaxOptions.xhrFields = { withCredentials: true };
if (method === 'insert') {
ajaxOptions.headers = {
[csrf['headerName']]: csrf['token']
};
}
},
});
};
Expand Down Expand Up @@ -59,7 +68,7 @@ $(() => {
lookup: {
dataSource: DevExpress.data.AspNet.createStore({
key: 'ID',
loadUrl: `${BASE_PATH}api/DataGridStatesLookup`,
loadUrl: `${BASE_PATH}/api/DataGridStatesLookup`,
}),
displayExpr: 'Name',
valueExpr: 'ID',
Expand Down Expand Up @@ -90,7 +99,7 @@ $(() => {
createDataGrid('grid1', store1);
createDataGrid('grid2', store2);

const hubUrl = `${BASE_PATH}dataGridCollaborativeEditingHub?GroupId=${groupId}`;
const hubUrl = `${BASE_PATH}/DataGridCollaborativeEditingHub?GroupId=${groupId}`;
const connection = new signalR.HubConnectionBuilder()
.withUrl(hubUrl, {
skipNegotiation: true,
Expand All @@ -114,3 +123,11 @@ $(() => {
});
});
});

(async () => {
const response = await fetch(`${BASE_PATH}/api/Common/GetAntiForgeryToken`, {
credentials: 'include'
});
const data = await response.text();
csrf = JSON.parse(data);
})();
Loading