python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
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

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions