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

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.