Hello,
I managed to send extra data. However, I would like to share with you a behavior I am facing with the below implementation:
What I realized, as long as the response has code 200 OK, the success function of $.ajax is the only function called.
In my case, I am returning errors when creating/updating data on server. However, I am returning 200 OK and adding errors as a property on the response data.
So for this, I had always to work with success function and check if errors are present, if so, then I call options.error(results);
The error function of $.ajax is never used. Are there cases it will be used?
Moreover, when options.error is called, the error function defined on DataSource is fired however, the input for that function doesn't contain the data I sent when I called options.error(result). Why is that? Shouldn't the data I passed in to options.error be passed in to the DataSource error function?
Moreover, I realized that when options.error() is called, the Grid doesn't cancelChanges, all changes done by user are kept the same.
Also, I tried to implement the DataSource error function, whereby I bind one time to Grid using jquery .one, however, it was never fired, but fired when I click on cancelChanges on Grid.
In general, is the above reliable to work with? In my case, I am loading data outside DataSource and hence the need to use this method.
Thank you
I managed to send extra data. However, I would like to share with you a behavior I am facing with the below implementation:
stateMap.projectStaffDs =
new
kendo.data.DataSource({
transport: {
read:
function
(options) {
options.success(stateMap.projectStaff);
},
create:
function
(options) {
$.ajax({
cache:
false
,
type:
"POST"
,
url: document.getBaseUrl() +
"/Services/SaveStaff"
,
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
data: JSON.stringify({ data: options.data.models, workspace: stateMap.userWorkspace.workspaceName }),
success:
function
(result) {
if
(result.errors) {
options.error(result);
}
else
if
(result.staff) {
options.success(result.staff);
}
},
error:
function
(result) {
options.error(result);
}
});
}
},
schema: {
model: projectStaffModel
},
batch:
true
,
pageSize: 1000
});
What I realized, as long as the response has code 200 OK, the success function of $.ajax is the only function called.
In my case, I am returning errors when creating/updating data on server. However, I am returning 200 OK and adding errors as a property on the response data.
So for this, I had always to work with success function and check if errors are present, if so, then I call options.error(results);
The error function of $.ajax is never used. Are there cases it will be used?
Moreover, when options.error is called, the error function defined on DataSource is fired however, the input for that function doesn't contain the data I sent when I called options.error(result). Why is that? Shouldn't the data I passed in to options.error be passed in to the DataSource error function?
Moreover, I realized that when options.error() is called, the Grid doesn't cancelChanges, all changes done by user are kept the same.
Also, I tried to implement the DataSource error function, whereby I bind one time to Grid using jquery .one, however, it was never fired, but fired when I click on cancelChanges on Grid.
In general, is the above reliable to work with? In my case, I am loading data outside DataSource and hence the need to use this method.
Thank you