fuzzybear
fuzzybear

Reputation: 2405

KnockoutJs update view model single observable from Json webservice

new to knockout, new to Js, I'm a dot net developer, trying to create a login screen with knockout, posting data fine, receiving response OK, just cant figure out how to update a single observable, please help...

function AppViewModel() {
this.email = ko.observable("Bergmail.com");
this.password = ko.observable("Password");
this.logonresult = ko.observable("logon resul");
//computed
this.Computedresult = ko.computed(function () {
    return this.email() + " " + this.password();
}, this);
    //behavious
this.Loginajax = function () {

    var self=this
    $.ajax("Indi-Dal-Json.asmx/CheckLogon" ,{
        data: ko.toJSON({ email: this.email,password: this.password}),
        type: "post", contentType: "application/json",
        success: function (ajaxjsondata) {
            {
                // var parsedjson = JSON.parse(result.b);
                //AppViewModel.logonresult = (result.d);
                self.logonresult = ajaxjsondata.d;
            }

        }
    });
   };
 }

Upvotes: 0

Views: 463

Answers (2)

fuzzybear
fuzzybear

Reputation: 2405

answered by Anders

self.logonresult(ajaxjsondata.d);

http://knockoutjs.com/documentation/observables.html#reading_and_writing_observables

Upvotes: 0

Anders
Anders

Reputation: 17554

self.logonresult is a observable, so you need to invoke it rather then overwrite its reference with a new value.

Change

self.logonresult = ajaxjsondata.d;

to

self.logonresult(ajaxjsondata.d);

http://knockoutjs.com/documentation/observables.html#reading_and_writing_observables

Upvotes: 1

Related Questions