Skip to content

Instantly share code, notes, and snippets.

@AlexShkor
Created October 23, 2013 08:58
Show Gist options
  • Save AlexShkor/7115055 to your computer and use it in GitHub Desktop.
Save AlexShkor/7115055 to your computer and use it in GitHub Desktop.
send model
var sendModel = function (url, model, successCallback, ignoreList) {
model.Loading(true);
var mapping = {
ignore: ignoreList
};
sendJson(url, ko.mapping.toJS(model,mapping), function(response) {
var defaultBehaviour = true;
if (successCallback) {
var result = successCallback(response);
if (result === false) {
defaultBehaviour = false;
}
}
if (defaultBehaviour) {
ko.mapping.fromJS(response, mapping, model);
}
model.Loading(false);
}, function() {
model.Loading(false);
});
};
function sendJson(url, json, success, error) {
$.ajax({
type: 'POST',
contentType: 'application/json,UTF-8',
dataType: "json",
url: url,
data: JSON.stringify(json),
success: function (response) {
if (success) {
success(response);
}
},
error: function (response) {
if (error) {
error(response);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment