how knockout js communicate with rest services

how knockout js communicate with rest services

how knockout js communicate with rest services

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.

http://stackoverflow.com/questions/19414227/using-knockout-js-to-communicate-with-rest-service

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^