how knockout js communicate with rest services
window.pcx.global = {
http://stackoverflow.com/questions/19414227/using-knockout-js-to-communicate-with-rest-service
window.pcx.global = {
baseUrl : "http://localhost:2000/restservicesURL",
contentType : "application/json; charset=utf-8",
dataType :"json"
}
var setHeaderRequest = function (xhr, companyId) {
xhr.setRequestHeader("CompanyID",
companyId);
}
var ajaxAsynch = function (url, data, CallType, callback) {
var global = window.pcx.global;
$.ajax({
url: global.baseUrl + url,
cache: false,
beforeSend: function (xhr) {
setHeaderRequest(xhr,
"1");
},
type: CallType,
contentType: global.contentType,
data: JSON.stringify(data),
dataType: global.dataType,
success: function (data) {
if (data !== undefined && data !== null) {
//TODO: Sucess logic.
callback(data);
}
}
})
.fail(
function (xhr, textStatus, err) {
//Log
the exception and alert to the end user.
});
}
It might help you.