Created
October 23, 2013 08:58
-
-
Save AlexShkor/7115055 to your computer and use it in GitHub Desktop.
send model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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