Skip to content

custom-unmapped model cannot be send with ajax-request #65

@fgieseke

Description

@fgieseke

Given: A custom mapping option to map and unmap a model.
Running this code
var model = ko.viewmodel.toModel(vm);
$.ajax({
type: "POST",
url: "/someService",
dataType: "json",
data: model
})

produces an exception because jquery (2.1.1) runs into this

    // Convert data if not already a string
    if ( s.data && s.processData && typeof s.data !== "string" ) {
        s.data = jQuery.param( s.data, s.traditional );
    }

and in the end executes the custom mapping function without passing an object to the map-function.
The reason for this is that the model still has 2 functions defined:
___$mapCustom and
___$unmapCustom

Workaround
var model = ko.viewmodel.toModel(vm);
delete model._$mapCustom; // cleanup model
delete model.
_$unmapCustom; // cleanup model
$.ajax({
type: "POST",
url: "/someService",
dataType: "json",
data: model
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions