[Fixed]-Knockout form to django-rest-framework

1👍

you haven’t declared observable’s in viewModel . so consider declaring to make things go smooth .

viewModel:

var viewModel = {
    firstname:ko.observable(),lastname:ko.observable(),
        mySubmit : function(formElement) {
            var formData = {
                'firstname' : viewModel.firstname() ,
                'lastname'  : viewModel.lastname()
            };

            $.ajax({
               url: '/echo/json/', //mocking ajax request 
                type: "POST",
                data: formData,
                contentType: "application/json; charset=utf-8",
                success: function (result){
                    alert("success");
                }
            });
        }
    };

ko.applyBindings(viewModel);

Working sample here

Leave a comment