Cant get data to observable in knockout js

Viewed 308

I am sending a ajax request to get data, with this code.

self.emailNotification = ko.observable();


    self.checkNotificationOfEmail = function (){
        $.ajax({
               type: 'POST',
               url: BASEURL + 'index.php/myprofile/checkNotificationOfEmail/' + auth,
               contentType: 'application/json; charset=utf-8'
           })
           .done(function(data) {
               alert(data);
            self.emailNotification(data.on_off);


           })
           .fail(function(jqXHR, textStatus, errorThrown) {
               self.errorMessage(errorThrown);
           })
           .always(function(data){               
           });
    };
    self.checkNotificationOfEmail(); 

The problem is when I alert ( data) I get object object, and when I try to push that data which I am getting into self.emailNotication observable, Its not working. Dont know what I am doing wrong. And when I try to alert self.emailNotification(data.on_off); I get undefined. When checking on console enter image description here

2 Answers
Related